C# Programming - MCQ Practice Questions
C# (.NET) MCQs — OOP, collections, LINQ & exception handling.
290 questions | 100% Free
A developer creates a class Library and another class Book. The Library class contains multiple Book objects. What is this relationship called?
In C# 9+, which feature allows you to create immutable reference types?
What is the output of the following code? class Animal { public virtual void Sound() { Console.WriteLine("Generic Sound"); } } class Dog : Animal { public override void Sound() { Console.WriteLine("Bark"); } } Dog dog = new Dog(); dog.Sound();
An abstract class Shape has an abstract method CalculateArea(). Which statement is true?
In C#, what is the difference between 'is' and 'as' operators?
A company develops a payment system using multiple payment methods (Credit Card, UPI, Wallet). Which OOP principle best applies here?
Consider a scenario where class C inherits from B, and B inherits from A. If all three have a method Display(), what does calling Display() on C object invoke?
In C# 10+, what is the purpose of the 'file-scoped type' modifier?
A developer needs to ensure that a method in a derived class cannot be overridden further. Which keyword should be used?
In C#, when implementing IDisposable pattern, what should a derived class do if the base class also implements it?
What is covariance in C# generics and interfaces?
A logging system needs to handle multiple logger types (File, Database, Console) interchangeably. Which design pattern combined with polymorphism best suits this?
In C# 13+ (projected features), nullable reference types help prevent which type of error?
Which of the following best describes encapsulation in C#?
What is the output of the following C# code? public class Base { public virtual void Display() { Console.WriteLine("Base"); } } public class Derived : Base { public override void Display() { Console.WriteLine("Derived"); } } Base obj = new Derived(); obj.Display();
A developer creates an abstract class Account with an abstract method CalculateInterest(). Two derived classes SavingsAccount and CurrentAccount implement this method differently. This scenario best demonstrates which OOP principle?
What is the difference between a class and a struct in C#?
In C#, what will be the output of the following code? class Test { public Test() { Console.WriteLine("Constructor"); } ~Test() { Console.WriteLine("Destructor"); } } Test t = new Test(); t = null;
An application needs to define behavior that multiple unrelated classes must follow. Which feature should be used?
What is the purpose of the 'base' keyword in C#?