C# Programming - MCQ Practice Questions
C# (.NET) MCQs — OOP, collections, LINQ & exception handling.
290 questions | 100% Free
Consider the following code. What will be the output? int x = 10; int y = 20; int z = x++ + ++y; Console.WriteLine(x + " " + y + " " + z);
Which of the following statements about structs and classes in C# is TRUE?
Which of the following is NOT a valid C# data type?
Consider: int[] arr = {1, 2, 3}; What happens when you try to resize it using Array.Resize(ref arr, 5)?
What is the difference between 'struct' and 'class' in C# regarding memory allocation?
Which of the following correctly describes method overloading in C#?
In C#, what is the primary purpose of the 'using' statement?
What will be the result of: string text = null; Console.WriteLine(text ?? "Default");
Which of the following correctly demonstrates method overloading in C#?
What is the output of: int x = 10; int y = x++; Console.WriteLine(x + ", " + y);
In C#, which keyword is used to implement multiple interface inheritance?
What will be the output of: decimal price = 19.99m; Console.WriteLine(price.GetType().Name);
In C# 2024, what is the latest feature for null-safety introduced in recent versions?
What is the output of: string s = "Hello"; Console.WriteLine(s.GetHashCode() == s.GetHashCode());
In C# 2024, which feature allows you to use pattern matching to deconstruct objects and filter simultaneously in a single expression?
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();
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();
What will happen if you try to override a non-virtual method?
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();
In C#, what happens when you apply the 'static' modifier to a method inside an interface (C# 11+)?