Both int? and Nullable<int> represent the same nullable integer type. int? is the shorthand syntax for Nullable<int>. They allow the variable to hold a null value in addition to integer values.
Q.42Medium
In C#, what does the 'params' keyword allow you to do?
Answer: B
'params' allows a method to accept a variable number of arguments of the same type as an array. For example: void Method(params int[] numbers) can accept 0 or more integers.
Q.43Medium
What will be the output of: string s1 = "Hello"; string s2 = "Hello"; Console.WriteLine(s1 == s2);
Answer: A
In C#, the == operator for strings compares their values, not references. Since both s1 and s2 contain "Hello", the result is true. This is different from object references comparison.
Q.44Medium
Which collection type in C# maintains insertion order and allows duplicate elements?
Answer: C
List<T> maintains insertion order and allows duplicates. HashSet<T> doesn't allow duplicates. Dictionary<K,V> maintains key-value pairs. SortedSet<T> keeps elements sorted without duplicates.
Q.45Medium
What is the purpose of the 'abstract' keyword in C#?
Answer: B
'abstract' keyword creates a class that serves as a blueprint for derived classes and cannot be instantiated directly. Abstract classes can contain abstract methods that must be implemented by derived classes.
Advertisement
Q.46Medium
Which of the following best describes LINQ in C#?
Answer: B
LINQ (Language Integrated Query) provides a unified syntax for querying different data sources like collections, databases, XML, etc. It allows developers to write queries in C# syntax.
Q.47Medium
What is the main purpose of the 'finally' block in C#?
Answer: B
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.
Q.48Medium
What is the output of: int x = 10; int y = x++; Console.WriteLine(x + " " + y);
Answer: B
Post-increment (x++) returns the current value first, then increments. So y gets 10, then x becomes 11.
Q.49Medium
Which keyword is used to create a constant variable in C# that cannot be changed?
Answer: A
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.
Q.50Medium
Which of the following is true about the 'var' keyword in C#?
Answer: B
var is implicitly typed. The type is inferred and set at compile-time based on the right-hand side assignment, providing type safety.
Q.51Medium
What is the output of: char ch = 'A'; Console.WriteLine((int)ch);
Answer: A
char 'A' has ASCII value 65. Casting to int gives the numeric ASCII value.
Q.52Medium
Which statement about method overloading in C# is correct?
Answer: B
Method overloading requires different parameter types, count, or order. Return type alone is not enough. C# fully supports overloading.
Q.53Medium
Which of the following correctly demonstrates the ternary operator in C#?
Answer: B
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.
Q.54Medium
Which of the following statements about ref and out parameters in C# is correct?
Answer: A
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.
Q.55Medium
What will be the behavior of the following code snippet?
string str = null;
string result = str?.ToUpper() ?? "DEFAULT";
Console.WriteLine(result);
Answer: A
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'.
Q.56Medium
What is the difference between 'is' and '==' operators when comparing object references in C#?
Answer: A
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.