Which of the following is a correct implementation of property with auto-backing field in C#?
Answer: A
Auto-properties with get; set; syntax automatically create backing fields. Option C is an expression-bodied property (read-only).
Q.62Hard
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.63Hard
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.64Hard
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.65Hard
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'.
Advertisement
Q.66Easy
In C#, which keyword is used to declare a variable that cannot be changed after initialization?
Answer: A
The 'const' keyword declares a constant whose value cannot be modified. Both 'const' and 'readonly' prevent changes, but 'const' is compile-time constant while 'readonly' is runtime constant.
Q.67Easy
What is the default access modifier for a class member in C# if not explicitly specified?
Answer: B
The default access modifier for class members in C# is 'private'. This means the member is only accessible within the same class unless explicitly specified otherwise.
Q.68Easy
Which statement correctly describes value types in C#?
Answer: B
Value types (int, double, struct, etc.) are stored on the stack memory. Reference types (class, interface) are stored on the heap. Value types don't require null checks like reference types.
Q.69Medium
What will be the output of the following code? int a = 5; int b = ++a; Console.WriteLine(a + " " + b);
Answer: B
++a is pre-increment, which increments 'a' to 6 first, then assigns it to 'b'. So both a and b become 6. Output is '6 6'.
Q.70Medium
Which of the following correctly demonstrates string interpolation in C# 6.0 and above?
Answer: C
String interpolation uses the prefixwithcurlybracestoembedexpressions.OptionCshowsthecorrectsyntax:"Hello {name}". The @ symbol creates verbatim strings, not interpolated strings.
Q.71Medium
In C#, what is the difference between 'struct' and 'class'?
Answer: B
struct is a value type stored on the stack, while class is a reference type stored on the heap. struct does not support inheritance from other structs/classes (except interfaces), while classes do.
Q.72Medium
Which method is used to convert a string to an integer in C#?
Answer: D
Both int.Parse() and Convert.ToInt32() can convert strings to integers. int.TryParse() is safer as it returns a boolean indicating success/failure. All are valid approaches.
Q.73Easy
What is the output of: bool result = (5 > 3) && (3 < 2); Console.WriteLine(result);
Answer: B
The && operator requires both conditions to be true. (5 > 3) is true, but (3 < 2) is false. Since one condition is false, the entire expression evaluates to false.
Q.74Medium
Which of the following is a nullable type in C#?
Answer: C
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.75Medium
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.76Medium
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.77Medium
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.78Medium
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.
Q.79Hard
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.80Hard
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".