Learn C# .Net MCQs
Prepare C# .Net MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following can be used to define an enumeration in C#?
1) enum Colors { Red, Green, Blue }
2) enum Colors : int { Red, Green, Blue }
3) enum { Red, Green, Blue }
4) None of the above
Answer : enum Colors { Red, Green, Blue }
What is the output of Console.WriteLine(3 > 2 ? "Yes" : "No");?
1) Yes
2) No
3) Error
4) None of the above
Answer : Yes
Which of the following statements about structs in C# is true?
1) Structs are reference types.
2) Structs can have constructors.
3) Structs cannot have methods.
4) None of the above
Answer : Structs can have constructors.
What is the output of Console.WriteLine("A".ToLower());?
1) a
2) A
3) Error
4) None of the above
Answer : a
Which of the following is not an exception type in C#?
1) FileNotFoundException
2) IndexOutOfRangeException
3) NullReferenceException
4) All of the above are exception types.
Answer : All of the above are exception types.
What is the output of Console.WriteLine(1 + 2 + "3");?
1) 33
2) 6
3) Error
4) None of the above
Answer : 33
Which of the following is used to implement a generic class in C#?
1) class MyClass<T> {}
2) class MyClass<T> : BaseClass {}
3) class MyClass[] {}
4) None of the above
Answer : class MyClass<T> {}
What is the output of Console.WriteLine(10 - 3 * 2);?
1) 4
2) 2
3) Error
4) None of the above
Answer : 4
Which of the following is the correct way to define a dictionary in C#?
1) Dictionary<int, string> dict = new Dictionary<int, string>();
2) Dictionary dict = new Dictionary();
3) Dictionary<string> dict = new Dictionary();
4) None of the above
Answer : Dictionary<int, string> dict = new Dictionary<int, string>();
What is the purpose of the "async" and "await" keywords in C#?
1) To create multi-threaded applications.
2) To define asynchronous methods.
3) To synchronize threads.
4) None of the above
Answer : To define asynchronous methods.