Category C#

Difference between ref and out keywords in C#

ref and out are pretty much like the pointers as in C/C++, they deal with the memory location of the object instead of the object directly.Mostly ref and out keywords are used in the method’s parameters ref void myFunction(ref Student obj); ref means that…

What is GUID

GUID stands for Globally Unique Identifier. GUID is the Microsoft implementation of the Distributed Computing Environment (DCE) Universally Unique Identifier(UUID). A GUID is a 128-bit value consisting of one group of 8 hexadecimal digits, followed by three groups of 4…

What is the Maximum Capacity of a String in .NET

The theoretical capacity of a String maybe 2,147,483,647 (2 Billion), because the Length property of the String returns an int, so the maximum length of a String is Int32.MaxValue (2,147,483,647) characters. But in practical, Since no single object in a .NET…

How to Merge two or more Lists in C#

Suppose we have 2 Lists of Products, and we want to make it one List. List<Product> products1 = GetProducts(cid1); List<Product> products2 = GetProducts(cid2); One way is to iterate the 2nd List, and add all elements to the 1st List, or iterate both…

Make a reserved keyword a Variable name in C#

Reserved keyword as variable name

In C# the ‘@‘ character is used to denote literals that explicitly do not adhere to the relevant rules in the language specification. If we use a keyword as the name for an identifier, we get a compile-time error “identifier expected,…

Remove item from List while iterating – C#

Remove items from list while iterating

Removing elements from List<> while iterating over the List, someone may simply try: foreach(char c in list)  {      list.Remove(c);  } But, When we execute this code, we will get System.InvalidOperationException with the message “Collection was modified; enumeration  operation may not execute.” The reason is: The…