iGET

C# Programming - MCQ Practice Questions

C# (.NET) MCQs — OOP, collections, LINQ & exception handling.

290 questions | 100% Free

Q.41Medium

A developer creates a class Library and another class Book. The Library class contains multiple Book objects. What is this relationship called?

Q.42Medium

In C# 9+, which feature allows you to create immutable reference types?

Q.43Medium

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();

Q.44Medium

An abstract class Shape has an abstract method CalculateArea(). Which statement is true?

Q.45Medium

In C#, what is the difference between 'is' and 'as' operators?

Q.46Hard

A company develops a payment system using multiple payment methods (Credit Card, UPI, Wallet). Which OOP principle best applies here?

Q.47Hard

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?

Q.48Hard

In C# 10+, what is the purpose of the 'file-scoped type' modifier?

Q.49Hard

A developer needs to ensure that a method in a derived class cannot be overridden further. Which keyword should be used?

Q.50Hard

In C#, when implementing IDisposable pattern, what should a derived class do if the base class also implements it?

Q.51Hard

What is covariance in C# generics and interfaces?

Q.52Hard

A logging system needs to handle multiple logger types (File, Database, Console) interchangeably. Which design pattern combined with polymorphism best suits this?

Q.53Medium

In C# 13+ (projected features), nullable reference types help prevent which type of error?

Q.54Easy

Which of the following best describes encapsulation in C#?

Q.55Medium

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();

Q.56Medium

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?

Q.57Medium

What is the difference between a class and a struct in C#?

Q.58Medium

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;

Q.59Medium

An application needs to define behavior that multiple unrelated classes must follow. Which feature should be used?

Q.60Easy

What is the purpose of the 'base' keyword in C#?