Consider the following code. What will be the output?
int x = 10;
int y = 20;
int z = x++ + ++y;
Console.WriteLine(x + " " + y + " " + z);
Answer: B
x++ returns 10 then increments x to 11. ++y increments y to 21 then returns 21. z = 10 + 21 = 31. Final output: 11 21 31
Q.2Hard
Which of the following statements about structs and classes in C# is TRUE?
Answer: B
In C#, structs are value types (stored on stack) while classes are reference types (stored on heap). This is a fundamental difference between the two.
Q.3Hard
Which of the following is NOT a valid C# data type?
Answer: C
C# has float (4 bytes) and double (8 bytes), but not float32. sbyte, uint, and decimal are valid types.
Q.4Hard
Consider: int[] arr = {1, 2, 3}; What happens when you try to resize it using Array.Resize(ref arr, 5)?
Answer: B
Array.Resize() creates a new array of specified size and copies elements from the original array using the ref parameter.
Q.5Hard
What is the difference between 'struct' and 'class' in C# regarding memory allocation?
Answer: C
Value types (struct) are allocated on the stack, while reference types (class) are allocated on the heap.
Advertisement
Q.6Hard
Which of the following correctly describes method overloading in C#?
Answer: B
Method overloading allows same method name with different signatures (parameter types, count, or order). Return type alone cannot differentiate overloaded methods.
Q.7Hard
In C#, what is the primary purpose of the 'using' statement?
Answer: B
The 'using' statement ensures that Dispose() is called on objects implementing IDisposable, preventing resource leaks. Importing namespaces is a different use of 'using'.
Q.8Hard
What will be the result of: string text = null; Console.WriteLine(text ?? "Default");
Answer: B
The null-coalescing operator (??) returns the right operand if the left is null. Since text is null, it prints 'Default'.
Q.9Hard
Which of the following correctly demonstrates method overloading in C#?
Answer: B
Method overloading requires same method name but different parameter types, count, or order. Return type alone is insufficient for overloading.
Q.10Hard
What is the output of: int x = 10; int y = x++; Console.WriteLine(x + ", " + y);
Answer: B
Post-increment (x++) returns the current value before incrementing. So y = 10, then x becomes 11. Output is '11, 10'.
Q.11Hard
In C#, which keyword is used to implement multiple interface inheritance?
Answer: D
C# implements multiple interface inheritance by listing interfaces separated by commas after the class name: class MyClass : Interface1, Interface2. There is no 'extends' or 'implements' keyword in C#.
Q.12Hard
What will be the output of: decimal price = 19.99m; Console.WriteLine(price.GetType().Name);
Answer: A
The GetType().Name returns the type name as "Decimal" (capitalized). The 'm' suffix specifies a decimal literal. The output shows the CLR type name, which is "Decimal".
Q.13Hard
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.14Hard
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.15Hard
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.