Learn C# .Net MCQs

Prepare C# .Net MCQs (Multiple choice Questions) for exam and job interviews.

Which of the following is the correct way to declare a dictionary in C#?

1) Dictionary<int, string> dict = new Dictionary<int, string>();

2) Dict<int, string> dict = new Dict<int, string>();

3) dictionary<int, string> dict = new dictionary<int, string>();

4) None of the above

Answer : Dictionary<int, string> dict = new Dictionary<int, string>();

Which of the following is used to stop the execution of a loop in C#?

1) break

2) stop

3) exit

4) None of the above

Answer : break

What is the output of Console.WriteLine("C# is awesome!".IndexOf("awesome"));?

1) 5

2) 6

3) 7

4) Error

Answer : 5

Which of the following is used to convert a string to an integer in C#?

1) int.Parse()

2) Convert.ToInt32()

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of Console.WriteLine("Hello".StartsWith("H"));?

1) true

2) false

3) Error

4) None of the above

Answer : true

Which of the following is used to define a method in C#?

1) void

2) function

3) def

4) None of the above

Answer : void

Which of the following is the correct way to handle multiple exceptions in C#?

1) try-catch-finally

2) try-multiple catch

3) try-finally

4) None of the above

Answer : try-catch-finally

What is the output of Console.WriteLine("C# is fun!".LastIndexOf("fun"));?

1) 6

2) 7

3) 8

4) Error

Answer : 6

Which of the following is used to perform explicit type conversion in C#?

1) cast

2) explicit

3) to

4) None of the above

Answer : cast

Which of the following is used to terminate a thread in C#?

1) Abort()

2) Terminate()

3) Stop()

4) None of the above

Answer : Abort()