Csharp Articles

Page 166 of 196

Association, Composition and Aggregation in C#

Samual Sam
Samual Sam
Updated on 19-Jun-2020 6K+ Views

Association in C#The association defines the relationship between an object in C#. An a one-to-one, one-to-many, many-to-one and many-to-many relationship can be defined between objects.For example, An Employee can be associated with multiple projects, whereas a project can have more than one employee.Composition in C#Under Composition, if the parent object is deleted, then the child object also loses its status.The composition is a special type of Aggregation and gives a part-of relationship.For example, A Car has an engine. If the car is destroyed, the engine is destroyed as well.Aggregation in C#Aggregation is a direct relation between objects in C#. It ...

Read More

A Deque Class in C#

Samual Sam
Samual Sam
Updated on 19-Jun-2020 1K+ Views

The Deque class uses a doubly-linked list to implement its collection of elements.  The doubly-linked lists should have two nodes i.e. front and back nodes. This helps in adding elements on the front and back of the Deque.With the Deque class, you have the ability to add and remove elements from both the sides. This is why Deque is said to be a double-ended queue.The Deque class has the following methods in the Queue class −ClearClears the collection of all of its elementsContainsWhether or not an object is in the collectionToArrayUse the ToArray() method to copy all of the elements ...

Read More

Difference between Method Overriding and Method Hiding in C#

Nitin Sharma
Nitin Sharma
Updated on 09-Jun-2020 3K+ Views

In C# there are two mechanisms for redefining or providing the new implementation of a method of parent class by its child class and these two mechanisms are known as Method overriding and Method hiding. Now on the basis of how method re-implementation is done we can distinguish between both of them.Following are the important differences between Method Overriding and Method Hiding.Sr. No.KeyMethod OverridingMethod Hiding1DefinitionMethod Overriding is a mechanism to achieve polymorphism where the super class and sub class have same methods, including the parameters and signature and, when you call it using the sub class object, the implementation in ...

Read More

Difference between SortedList and SortedDictionary in C#

Nitin Sharma
Nitin Sharma
Updated on 09-Jun-2020 957 Views

Both SortedList and SortedDictionary in C# are the types of data structures used for data storage, now on the basis of characteristics and nature we can distinguish between both of them.Following are the important differences between SortedList and SortedDictionary.Sr. No.KeySortedListSortedDictionary1Memory organizationSortedList requires low memory for storage hence the memory status in its case is overhead.On other hand SortedDictionary requires more memory for storage so memory status in its case is not bottlenecked.2DesignedSortedList is internally implemented as in sortedList the elements are stored in a continuous block in memory.On other hand in SortedDictionary the elements are stored in separate object that ...

Read More

Difference between Class and Structure in C#

Nitin Sharma
Nitin Sharma
Updated on 09-Jun-2020 1K+ Views

In order to differentiate between Class and Structure, we have to first understand that both structure and class seems to be equivalent in the context of holding and defining the data. Both of these could define as well as hold some default values in their data members. But if we consider them beyond this context then Class provides more flexibility along with functionality as compared to the Structure.Following are the important differences between Class and Structure.Sr. No.KeyClassStructure1Data TypeData defined in a class is stored in the memory as a reference and has particular address in order to get accessed, so ...

Read More

Boolean.Parse() Method in C#

AmitDiwan
AmitDiwan
Updated on 24-Apr-2020 2K+ Views

The Boolean.Parse() method in C# is used to convert the specified string representation of a logical value to its Boolean equivalent.SyntaxFollowing is the syntax −public static bool Parse (string val);Above, the parameter value is a string containing the value to convert.ExampleLet us now see an example to implement the Boolean.Parse() method −using System; public class Demo {    public static void Main(){       bool b;       b = bool.Parse("FALSE");       Console.WriteLine("After parsing = "+b);    } }OutputThis will produce the following output −After parsing = FalseExampleLet us see another example −using System; public class ...

Read More

DateTimeOffset.FromFileTime() Method in C#

AmitDiwan
AmitDiwan
Updated on 21-Apr-2020 80 Views

The DateTimeOffset.FromFileTime() method in C# is used to convert the specified Windows file time to an equivalent local time.SyntaxFollowing is the syntax −public static DateTimeOffset FromFileTime (long time);Above, time is the Windows file time, in ticks.ExampleLet us now see an example to implement the DateTimeOffset.FromFileTime() method −using System; public class Demo {    public static void Main() {       DateTimeOffset offset = DateTimeOffset.FromFileTime(0);       Console.WriteLine("DateTimeOffset = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", offset);    } }OutputThis will produce the following output −DateTimeOffset = 01 January 1601, 12:00:00ExampleLet us now see another example to implement the DateTimeOffset.FromFileTime() method −using ...

Read More

Type.GetEnumName() Method in C#

AmitDiwan
AmitDiwan
Updated on 21-Apr-2020 108 Views

The Type.GetEnumName() method in C# returns the name of the constant that has the specified value, for the current enumeration type.SyntaxFollowing is the syntax −public virtual string GetEnumName (object val);Above, Val is the value whose name is to be retrieved.ExampleLet us now see an example to implement the Type.GetEnumName() method −using System; public class Demo {    enum Vehicle {Car, Bus, Bike}    public static void Main(){       Vehicle v = Vehicle.Bike;       Type type = v.GetType();       string str = type.GetEnumName(v);       Console.WriteLine("GetEnumName() to return the constant name = " + ...

Read More

DateTime.ToFileTimeUtc() Method in C#

AmitDiwan
AmitDiwan
Updated on 21-Apr-2020 269 Views

The DateTime.ToFileTimeUtc() method in C# is used to convert the value of the current DateTime object to a Windows file time.SyntaxFollowing is the syntax −public long ToFileTimeUtc ();ExampleLet us now see an example to implement the DateTime.ToFileTimeUtc() method −using System; public class Demo {    public static void Main() {       DateTime d = new DateTime(2019, 05, 10, 6, 10, 25);       Console.WriteLine("Date = {0}", d);       long res = d.ToFileTimeUtc();       Console.WriteLine("Windows file time (Utc) = {0}", res);    } }OutputThis will produce the following output −Date = 5/10/2019 6:10:25 AM ...

Read More

Coupling in C#

George John
George John
Updated on 14-Apr-2020 3K+ Views

Coupling shows the relationship between modules in C# or you can say the interdependence between modules.There are two types of coupling i.e tight and loose coupling.Loose CouplingLoose coupling is preferred since through it changing one class will not affect another class. It reduces dependencies on a class. That would mean you can easily reuse it.Writing loosely coupled code has the following advantages −One module won’t break other modulesEnhances testabilityCode is easier to maintainGets less affected by changes in other components.Tight CouplingIn Tight Coupling, the classes and objects are dependent on each other and therefore reduce re-usability of code.

Read More
Showing 1651–1660 of 1,951 articles
« Prev 1 164 165 166 167 168 196 Next »
Advertisements