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.82Medium
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.83Easy
Which of the following is NOT a value type in C#?
Answer: B
string is a reference type in C#, while int, float, and bool are value types.
Q.84Medium
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.85Easy
Which of the following correctly declares and initializes an array in C#?
Answer: A
Option A is the correct C# syntax. Option B is C-style, Option C has wrong syntax, and Option D has incorrect keyword placement.
Advertisement
Q.86Medium
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.87Easy
What will be the result of: Console.WriteLine(310);
Answer: C
Since both 10 and 3 are integers, integer division occurs, resulting in 3 (the decimal part is truncated).
Q.88Medium
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.89Medium
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.90Medium
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.91Medium
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.92Hard
In C# 2024, what is the latest feature for null-safety introduced in recent versions?
Answer: D
C# has progressively introduced nullable reference types, required keyword (C# 11), and init-only properties (C# 9) for better null-safety and immutability.
Q.93Hard
What is the output of: string s = "Hello"; Console.WriteLine(s.GetHashCode() == s.GetHashCode());
Answer: A
GetHashCode() on the same string returns the same hash code value, so comparison is true. Strings are immutable in C#.
Q.94Easy
Which collection type in C# is best suited for key-value pair storage with unique keys?
Answer: B
Dictionary<K, V> stores key-value pairs and ensures unique keys. List stores ordered values, HashSet stores unique values only, Queue is FIFO.
Q.95Medium
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.96Medium
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.97Hard
In C# 2024, which feature allows you to use pattern matching to deconstruct objects and filter simultaneously in a single expression?
Answer: A
C# 12 (2024) introduced advanced list patterns that allow filtering and deconstructing collections in pattern matching expressions, improving code readability and efficiency.
Q.98Medium
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.
Q.99Easy
Consider this code: int[] arr = new int[5]; foreach(var item in arr) { Console.Write(item + " "); } What is the output?
Answer: B
Arrays in C# are automatically initialized with default values. For int arrays, the default value is 0. Therefore, the output will be five zeros separated by spaces.
Q.100Easy
Which of the following is a correct way to declare a property with auto-implementation in C#?
Answer: A
Auto-implemented properties in C# use the syntax: public Type PropertyName { get; set; } without explicitly defining the backing field.