Tag: C#

Use of var keyword in C#

The var keyword in C# was introduced from C# 3.0 and it beings in the feature of local type inference or implicit type variable in C#. LINQ is one of the case where var keyword can be widely used in C#. Eg: In the above example, the initialization of the name was done using “string” and hence name will be implicitly treated as string. Note…

What are the difference between class and structure in C#?

What are the difference between class and structure in C#? Structure Struct are value types. They can be empty but a null cannot be assigned to Struct Structs cannot contain explicit parameterless constructors. Doesn’t support Inheritance and cannot use the protected or protected internal modifier. A Struct always has a built-in public default constructor. Cannot use the “as” operator. Cannot have a destructor Cannot be…

What is the Difference between String and String Builder in C#?

What is the Difference between String and String Builder in C#? The string instance is immutable i.e. each time when you change the string m a new instance is returned. This can be inefficient sometimes The StringBuilder allows the developers to have a mutable string. This is a good option in case you want to modify / append string many times.

How to Sort Array Elements in Descending Order in C#?

The Array class includes static method called Sort which can be used to sort the array in ascending order. After using the Sort method, one can use the Reverse method to sort the array back to descending order. How to Sort Array Elements in Descending Order in C#? Below is a sample code snippet demonstrating sorting of array elements in Descending order in C#.

How to Sort Array Elements in Ascending Order in C#?

The Array class includes static method called Sort which can be used to sort the array in ascending order in C#. Array.Sort(<arry>); How to Sort Array Elements in Ascending Order in C#? Below is a sample code snippet demonstrating sorting of array elements in ascending order in C#.

Lock keyword in C#

Want to get the mutual exclusion lock for a given object or a block of statement? If yes, you can use the lock keyword in C# which marks the start of the critical section. The lock keyword may be useful especially when you are using threading in your application. It ensures that only one thread can enter and use the critical section. If another thread…

Liked this content?. Please spread the word :)