Govt. Exams
Entrance Exams
In C#, 'int?' is used to declare a nullable integer. A regular 'int' cannot be assigned null. int* is a pointer (unsafe code), not a nullable type.
int.Parse() converts a string to an integer. Direct casting doesn't work for strings. Convert.ToInt32() would throw an exception if the string is not a valid number. The 'as' operator doesn't work for strings to primitives.
For strings, '==' compares references (memory addresses) while Equals() compares the actual string values. However, C# has optimized string comparison, so both often behave similarly for string literals.
The 'const' keyword is used to declare constants in C#. 'final' is Java syntax. While 'readonly' can be used, 'const' is the proper keyword for compile-time constants.
int is a value type (primitive type). string, object, and arrays are reference types in C#.
int x = 5;
int y = ++x;
Console.WriteLine(x + " " + y);
++x is pre-increment. It increments x first (x becomes 6), then assigns the value to y. So both x and y are 6.