Govt. Exams
Entrance Exams
Advertisement
Topics in C# Programming
What is the difference between '==' and 'Equals()' when comparing strings in C#?
Correct Answer:
A. '==' compares references, Equals() compares values
EXPLANATION
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.
What is the correct way to declare a constant variable in C#?
Correct Answer:
A. const int MAX = 100;
EXPLANATION
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.
Which of the following data types in C# is a value type?
Correct Answer:
B. int
EXPLANATION
int is a value type (primitive type). string, object, and arrays are reference types in C#.
What will be the output of the following code snippet?
int x = 5;
int y = ++x;
Console.WriteLine(x + " " + y);
int x = 5;
int y = ++x;
Console.WriteLine(x + " " + y);
Correct Answer:
B. 6 6
EXPLANATION
++x is pre-increment. It increments x first (x becomes 6), then assigns the value to y. So both x and y are 6.