TopicCode
Escape character in C#Console.WriteLine(“Hello ” World”);
Console.WriteLine(“Hello \t World”);
String formattingConsole.WriteLine({0} , Hello);
Convert full string to uppercases.ToUpper()
Convert only one char to uppercasechar.ToUpper(s[0])
Substring printingConsole.WriteLine(s[2..]);
Array initializationint[] arr = new int[5]; or,  int[] arr = new int[] { 1, 3, 5, 7, 9 }; or, int[] arr = { 1, 3, 5, 7, 9 };
Multidimensional arrayint[,] array = new int[4, 2];
Jagged arrayint[][] jaggedArray = new int[3][];
Decimal to binaryConsole.WriteLine(Convert.ToString(m, toBase: 2));
Decimal to octalConsole.WriteLine(Convert.ToString(x, toBase: 8));
Bitwise NOT for toggling binary bitint x = ~x;
Maximum of two valuesMath.Max(sum, h)
Ceiling divisionMath.Ceiling((double)n / 2);
Swap values(a, b) = (b, a);
HashSetHashSet myhash = new HashSet();
myhash.Add(“C”);
myhash.Clear();
List (like vector)List list = new List();
list.Add(12);
Console.Write(“{0} ”, list[i]);
Dictionary (like pair in C++)Dictionary<string, int> figures = new Dictionary<string, int>()
{ “Tetrahedron”, 4}, {“Cube”, 6}, {“Octahedron”, 8}, {“Dodecahedron”, 12}, {“Icosahedron”, 20}
Count occurrences using Dictionary[See the provided code]
String sorting in C#String.Concat(str.OrderBy(c ⇒ c));
string SortString(string input){char[] characters = input.ToArray();Array.Sort(characters);return new string(characters);}
s = SortString(s);
Array sorting and reversingArray.Sort(myarr);
Array.Reverse(myarr);
Merge two arraysint[] arr = arr1.Concat(arr2).ToArray();
Remove duplicates from an arrayarr = arr.Distinct().ToArray();
Maximum value in an arrayint maxi = arr.Max();
Length of an arrayint len = arr.Length;
Sum of elements in an arrayint total = arr.Sum();
Count occurrences of a specific value in an arrayint one = arr.Where(i ⇒ i == 1).Count();
Lambda expressions[See the provided code]
Input for 1D arrayarr = Array.ConvertAll(Console.ReadLine().Split(’ ’), int.Parse);
Input for 2D array[See the provided code]
Accessibility levelspublic < internal < protected < private
int.Parse vs Convert.ToInt32[Provided explanation]
Check object typeif (obj is string)
if (!(obj is int))
Primitive types in C#Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, Single
Object class methods[Provided explanation and code]