Govt. Exams
Entrance Exams
The 'is' operator checks reference equality by default and is used for type checking, while '==' can be overloaded by classes to provide custom equality logic.
string str = null;
string result = str?.ToUpper() ?? "DEFAULT";
Console.WriteLine(result);
The null-coalescing operator (?.) with null-coalescing assignment (??) ensures that when str is null, the expression evaluates to null, and then ?? provides the default value 'DEFAULT'.
ref parameters must be initialized before being passed to a method, while out parameters don't require initialization beforehand. The method must assign a value to out parameters before returning.
Option B is correct as both branches return int (1 or 0). Option A has type mismatch (string in int). Option C has wrong syntax. Option D has type mismatch.
Method overloading requires different parameter types, count, or order. Return type alone is not enough. C# fully supports overloading.
char 'A' has ASCII value 65. Casting to int gives the numeric ASCII value.
var is implicitly typed. The type is inferred and set at compile-time based on the right-hand side assignment, providing type safety.
const creates a compile-time constant. readonly allows assignment only in constructor or at declaration. static makes it class-level, and fixed is for pointers.
Post-increment (x++) returns the current value first, then increments. So y gets 10, then x becomes 11.
The 'finally' block executes regardless of whether an exception is thrown or caught. It is used for cleanup operations like closing file streams or database connections.