Learn C# .Net MCQs
Prepare C# .Net MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following is a correct way to create a property in C#?
1) public int MyProp { get; set; }
2) public int MyProp = 0;
3) int MyProp();
4) None of the above
Answer : public int MyProp { get; set; }
What is the output of Console.WriteLine("123".Length);?
1) 3
2) 2
3) Error
4) None of the above
Answer : 3
Which of the following is used to declare an interface in C#?
1) interface IMyInterface {}
2) class IMyInterface {}
3) IMyInterface {}
4) None of the above
Answer : interface IMyInterface {}
What is the output of Console.WriteLine(10 / 0);?
1) Infinity
2) 0
3) Error
4) None of the above
Answer : Error
Which of the following is not a valid way to define a method in C#?
1) public void MyMethod() {}
2) void MyMethod() {}
3) public MyMethod() {}
4) None of the above
Answer : public MyMethod() {}
What is the output of Console.WriteLine("abc".IndexOf("b"));?
1) 1
2) 2
3) 0
4) Error
Answer : 1
Which of the following is the correct way to define an event in C#?
1) public event EventHandler MyEvent;
2) public MyEvent EventHandler;
3) event MyEventHandler;
4) None of the above
Answer : public event EventHandler MyEvent;
What is the output of Console.WriteLine("Hello"[0]);?
1) H
2) Hello
3) Error
4) None of the above
Answer : H
Which of the following is used to handle multiple exceptions in C#?
1) catch (Exception1 | Exception2 e)
2) catch (Exception e1, Exception e2)
3) catch (Exception e)
4) None of the above
Answer : catch (Exception e)
What does the "new" keyword do in C#?
1) Creates a new instance of an object
2) Declares a variable
3) Creates a method
4) None of the above
Answer : Creates a new instance of an object