Learn C# .Net MCQs
Prepare C# .Net MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following is a valid way to declare a constant in C#?
1) const int x = 5;
2) readonly int x;
3) int x = 5;
4) None of the above
Answer : const int x = 5;
What is the output of Console.WriteLine(2 * 3 + 1);?
1) 7
2) 6
3) Error
4) None of the above
Answer : 7
Which of the following can be used to serialize an object in C#?
1) BinaryFormatter
2) JsonSerializer
3) XmlSerializer
4) All of the above
Answer : All of the above
Which of the following is used to iterate over a collection in C#?
1) foreach
2) for
3) while
4) do-while
Answer : foreach
What does the "var" keyword do in C#?
1) Declares a variable with a specific type
2) Infers the type of a variable
3) Defines a method
4) None of the above
Answer : Infers the type of a variable
Which of the following statements is true about interfaces in C#?
1) They can contain implementation.
2) They can only have method signatures.
3) They can inherit from classes.
4) None of the above
Answer : They can only have method signatures.
What is the output of Console.WriteLine(5 == 5 && 4 > 2);?
1) true
2) false
3) Error
4) None of the above
Answer : true
Which of the following is NOT a C# access modifier?
1) internal
2) private
3) protected
4) global
Answer : global
What is the output of Console.WriteLine(10 % 3);?
1) 1
2) 3
3) 2
4) Error
Answer : 1
Which of the following types can be used as a nullable type in C#?
1) int?
2) string?
3) double?
4) All of the above
Answer : All of the above