iGET

C# Programming - MCQ Practice Questions

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

290 questions | 100% Free

Q.1Hard

Consider the following code. What will be the output?
int x = 10;
int y = 20;
int z = x++ + ++y;
Console.WriteLine(x + " " + y + " " + z);

Q.2Hard

Which of the following statements about structs and classes in C# is TRUE?

Q.3Hard

Which of the following is NOT a valid C# data type?

Q.4Hard

Consider: int[] arr = {1, 2, 3}; What happens when you try to resize it using Array.Resize(ref arr, 5)?

Q.5Hard

What is the difference between 'struct' and 'class' in C# regarding memory allocation?

Q.6Hard

Which of the following correctly describes method overloading in C#?

Q.7Hard

In C#, what is the primary purpose of the 'using' statement?

Q.8Hard

What will be the result of: string text = null; Console.WriteLine(text ?? "Default");

Q.9Hard

Which of the following correctly demonstrates method overloading in C#?

Q.10Hard

What is the output of: int x = 10; int y = x++; Console.WriteLine(x + ", " + y);

Q.11Hard

In C#, which keyword is used to implement multiple interface inheritance?

Q.12Hard

What will be the output of: decimal price = 19.99m; Console.WriteLine(price.GetType().Name);

Q.13Hard

In C# 2024, what is the latest feature for null-safety introduced in recent versions?

Q.14Hard

What is the output of: string s = "Hello"; Console.WriteLine(s.GetHashCode() == s.GetHashCode());

Q.15Hard

In C# 2024, which feature allows you to use pattern matching to deconstruct objects and filter simultaneously in a single expression?

Q.16Hard

What is the output of the following?
class A { public void Test() { Console.WriteLine("A"); } }
class B : A { public new void Test() { Console.WriteLine("B"); } }
A a = new B();
a.Test();

Q.17Hard

Consider the following code. What will be the output?
interface I1 { void Show(); }
interface I2 { void Show(); }
class C : I1, I2 { public void Show() { Console.WriteLine("C"); } }
C obj = new C();
obj.Show();

Q.18Hard

What will happen if you try to override a non-virtual method?

Q.19Hard

What is the output of the following code?
class Base { public virtual void Method() { Console.WriteLine("Base"); } }
class Derived : Base { public override void Method() { base.Method(); Console.WriteLine("Derived"); } }
Derived d = new Derived();
d.Method();

Q.20Hard

In C#, what happens when you apply the 'static' modifier to a method inside an interface (C# 11+)?