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.22Easy
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.23Easy
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.24Easy
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.25Easy
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.26Easy
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.27Easy
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.28Easy
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.29Easy
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.
Q.30Easy
In C#, what is the default access modifier for class members?
Answer: B
The default access modifier for class members in C# is 'private', which restricts access to within the class only.
Q.31Easy
Which keyword is used to create a derived class in C#?
Answer: C
In C#, the colon (:) is used to indicate inheritance. For example, 'class Child : Parent' creates a derived class.
Q.32Easy
In C#, can a class inherit from multiple classes?
Answer: B
C# does not support multiple class inheritance to avoid the diamond problem. However, a class can implement multiple interfaces.
Q.33Easy
Which of the following correctly demonstrates an abstract class with an abstract method in C#?
Answer: A
An abstract class uses the 'abstract' keyword, and abstract methods must be declared without implementation inside abstract classes.
Q.34Easy
Which access modifier allows a member to be accessed only within the same assembly?
Answer: B
'internal' access modifier restricts member access to the same assembly only. This is useful for creating assembly-wide internal APIs.
Q.35Easy
What is the output of using 'nameof()' operator on a property in C#?
Answer: B
'nameof()' operator (C# 6+) returns the name of a variable, type, or member as a string literal, useful for logging and validation.
Q.36Easy
What happens when you mark a class with the 'sealed' modifier?
Answer: B
'sealed' keyword prevents a class from being inherited. This is useful for security and performance optimization when you want to prevent further derivation.
Q.37Easy
What does the 'base' keyword do in a derived class method in C#?
Answer: B
'base' keyword is used to access base class members, particularly useful in constructors to call base class constructors or override base methods.
Q.38Easy
Which of the following demonstrates proper encapsulation in C#?
Answer: B
Proper encapsulation uses private fields with public properties, providing controlled access and allowing for future validation logic.
Q.39Easy
What is the output behavior of ToString() method when not overridden in a custom class?
Answer: B
Default ToString() (inherited from object) returns the fully qualified namespace and class name. Custom implementations are recommended for meaningful string representation.
Q.40Easy
In C#, which access modifier allows a member to be accessed only within the same class?
Answer: A
The 'private' access modifier restricts access to members within the same class only. It is the most restrictive access level in C#.