C# Online Test - MCQ Questions

Welcome to the C# Programming Online Test! This assessment is designed to evaluate your knowledge and expertise in C#, a powerful, versatile language used extensively in various types of software development, including web, mobile, and desktop applications. The test comprises 25 multiple-choice questions, each embedded with a C# code snippet to assess a wide range of your programming skills.

Each question targets different aspects of the C# language, from basic syntax and control structures to more complex concepts like exception handling, collections, and LINQ. This setup helps gauge both your theoretical understanding of C# principles and your practical ability to apply them in real-world scenarios.

Before beginning the test, ensure you read each question carefully and consider the code snippets provided to select the most appropriate answer. Detailed explanations are provided with each answer to enhance your understanding and solidify your knowledge of key concepts.

Good luck! We hope this test proves challenging and educational, helping you refine your skills and deepen your understanding of C# programming.

1. What is the output of the following C# code?

int x = 5;
int y = 2;
Console.WriteLine(x / y);
a) 2.5
b) 2
c) 5
d) None of the above

2. What will the following C# code print?

int x = 5;
int y = 3;
Console.WriteLine(x + y);
a) 8
b) 53
c) 15
d) Syntax error

3. What does the following C# code output?

bool a = true;
bool b = false;
Console.WriteLine(a && b);
a) True
b) False
c) 1
d) 0

4. What is the output of the following C# code?

for (int i = 0; i < 5; i++) {
    Console.Write(i + " ");
}
a) 0 1 2 3 4
b) 1 2 3 4 5
c) 0 1 2 3 4 5
d) 1 2 3 4

5. What does the following C# code print?

Console.WriteLine(10 % 3);
a) 3
b) 1
c) 10
d) None of the above

6. What will be the output of the following C# code?

string x = "Hello";
string y = "World";
Console.WriteLine(x + " " + y);
a) Hello World
b) HelloWorld
c) Hello
d) World

7. What does this C# code output?

int[] arr = {1, 2, 3};
Console.WriteLine(arr[1]);
a) 1
b) 2
c) 3
d) Error

8. What will the following C# code snippet output?

int x = 5;
int y = x;
y += 2;
Console.WriteLine(x);
a) 5
b) 7
c) Error
d) None

9. What does the following C# code print?

void Main() {
    var numbers = new List<int> {1, 2, 3};
    numbers.Add(4);
    Console.WriteLine(numbers.Count);
}
a) 3
b) 4
c) 5
d) None of the above

10. What is the result of executing the following C# code?

bool isEqual = (5 == 5);
Console.WriteLine(isEqual);
a) True
b) False
c) 1
d) 0

11. What will this C# function output?

public static int Multiply(int x, int y) {
    return x * y;
}
Console.WriteLine(Multiply(5, 3));
a) 15
b) 8
c) 5
d) None of these

12. What is the output of the following C# code?

char[] letters = {'a', 'b', 'c'};
Console.WriteLine(letters.Length);
a) 1
b) 2
c) 3
d) None of these

13. What does the following C# code return?

int x = 10;
int y = 20;
int z = x > y ? x : y;
Console.WriteLine(z);
a) 10
b) 20
c) 30
d) 0

14. What is the output of this C# program?

try {
    int result = 10 / 0;
}
catch (DivideByZeroException) {
    Console.WriteLine("Division by zero!");
}
a) 10
b) 0
c) Division by zero!
d) Error

15. What will the following C# code snippet output?

decimal a = 1.0m;
decimal b = 3.0m;
Console.WriteLine(a / b);
a) 0.333
b) 0.33
c) 0.3333333333333333333333333333
d) None of these

16. What does this C# code print?

Console.WriteLine("C#".ToLower());
a) c#
b) C#
c) csharp
d) Csharp

17. What is the outcome of the following C# code?

int[] nums = new int[3];
Console.WriteLine(nums[0]);
a) 1
b) 0
c) null
d) Error

18. What will this C# code output?

string greeting = "Hello, world!";
Console.WriteLine(greeting.Substring(0, 5));
a) Hello
b) Hello,
c) H
d) Error

19. What does the following C# code return?

List<int> numbers = new List<int>() {10, 20, 30};
Console.WriteLine(numbers[1]);
a) 10
b) 20
c) 30
d) None of these

20. What is the result of executing the following C# code?

string[] pets = {"dog", "cat", "bird"};
Array.Reverse(pets);
Console.WriteLine(pets[0]);
a) dog
b) cat
c) bird
d) Error

21. What will the following C# code snippet output?

int? x = null;
Console.WriteLine(x.HasValue);
a) True
b) False
c) Error
d) None

22. What is the output of the following C# code?

int x = 5;
Console.WriteLine(x.Equals(5));
a) True
b) False
c) 1
d) None of these

23. What will be the output of the following C# program?

Console.WriteLine(DateTime.Now.Year);
a) The current year
b) The current month
c) The current day
d) Error

24. What does this C# code output?

string s = "123";
int x;
bool success = int.TryParse(s, out x);
Console.WriteLine(success);
a) True
b) False
c) 123
d) Error

25. What is the result of this C# function?

public bool IsEven(int num) {
    return num % 2 == 0;
}
Console.WriteLine(IsEven(10));
a) True
b) False
c) Error
d) None

Comments