wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C# Debugging Practice Quiz

Total questions: 22

Worksheet time: 11mins

Name
Class
Date
1.

What is the syntax error in the following C# code snippet?
int number = 10
Console.WriteLine(number);

a)

Missing semicolon after `int number = 10`

b)

Incorrect variable type

c)

Missing parentheses in `Console.WriteLine`

d)

Incorrect method name

2.

Which of the following is a common debugging tool in Visual Studio?

a)

Code Formatter

b)

Breakpoints

c)

Code Refactor

d)

Code Snippets

3.

Identify the syntax error in this C# code:

string name = "John";
if (name = "John") { Console.WriteLine("Hello, John!"); }

a)

Incorrect use of `Console.WriteLine`

b)

Missing semicolon after `Console.WriteLine("Hello, John!")`

c)

Assignment operator `=` should be `==` in the `if` statement

d)

Incorrect string declaration

4.

Which of the following is NOT a feature of the Visual Studio Debugger?

a)

Step Into

b)

Step Over

c)

Step Back

d)

Step Out

5.

What is the syntax error in the following C# code?
void SampleFunction() {
Console.WriteLine("The result is: " + result);
}

a)

Missing semicolon

b)

`result` is not defined

c)

Incorrect use of `Console.WriteLine`

d)

Incorrect string concatenation

6.

Which of the following is a benefit of using a debugger?

a)

It automatically fixes syntax errors

b)

It helps identify logical errors in code

c)

It optimises code for better performance

d)

It formats code according to style guidelines

7.

What is the syntax error in this C# code snippet?
for (int i = 0; i < 10; i++) {
Console.WriteLine(i)
}

a)

Incorrect loop condition

b)

Missing semicolon after `Console.WriteLine(i)`

c)

Incorrect variable declaration

d)

Missing curly braces

8.

What is the purpose of the `try-catch` block in C#?

a)

To declare variables

b)

To handle exceptions

c)

To define classes

d)

To create loops

9.

Which of the following is NOT a syntax error in C#?

a)

Missing semicolon

b)

Incorrect variable type

c)

Using `=` instead of `==` in a condition

d)

Using a reserved keyword as a variable name

10.

What is the syntax error in this C# code?
int[] numbers = {1, 2, 3, 4, 5};
Console.WriteLine(numbers[5]);

a)

Incorrect array declaration

b)

Index out of range

c)

Missing semicolon

d)

Incorrect use of `Console.WriteLine`

11.

Which of the following is a feature of the Visual Studio Debugger?

a)

Code Refactoring

b)

Code Snippets

c)

Watch Window

d)

Code Formatting

12.

What is the syntax error in this C# code snippet?
void public DisplayMessage() {
Console.WriteLine("Hello, World!") ;
}

a)

Missing semicolon after `Console.WriteLine("Hello, World!")`

b)

Incorrect method declaration

c)

Missing return type

d)

Incorrect use of `Console.WriteLine`

13.

A program is supposed to print all elements in an array. However, it misses the last element.

int[] numbers = { 1, 2, 3, 4, 5 };

for (int i = 0; i < numbers.Length - 1; i++) // Bug here

{

Console.WriteLine(numbers[i]);

}

What’s the issue?

a)

Incorrect array initialisation

b)

Loop ends too early

c)

Array index out of bounds

14.

A program hangs indefinitely due to a loop. What's the issue?

int i = 0;

while (i < 100)

{

Console.WriteLine(i);

}

What’s the fix?

a)

Add i++; inside the loop

b)

Use a for 10 loop instead

c)

No issues to fix

15.

A program is supposed to check if a word is "Hello", but it fails for "hello".
string input = "hello";

if (input == "Hello") // Bug here

{

Console.WriteLine("Matched!");

}

a)

Use ToLower() or ToUpper() for comparison

b)

Change the condition to if (input.Equals("Hello", true))

c)

Use a regular expression

16.

What will happen if you run the following code?
int a = 10, b = 0;

Console.WriteLine(a / b);

a)

It will throw a DivideByZeroException

b)

It will print 0

c)

It will output a long floating number

17.

The program should print "Even" for even numbers, but it always prints "Odd".
int num = 4;

if (num % 2 == 1) // Bug here

{ Console.WriteLine("Odd"); }

else

{ Console.WriteLine("Even"); }

What’s the issue?

a)

Incorrect modulus operation

b)

Incorrect condition for even numbers

c)

The else block is missing

18.

The program throws an exception when accessing an array element. What's the problem?

int[] numbers = { 1, 2, 3 };

Console.WriteLine(numbers[3]);

a)

Accessing an element out of bounds

b)

Index starts from 1

c)

Array is empty

19.

The program crashes with a NullReferenceException.

string name = null;

Console.WriteLine(name.ToUpper());

How to fix this?

a)

Add a null check before accessing name

b)

Assign a default value to name

c)

Both A and B

20.

What will happen if you run this code?
int number = "123";

a)

It will print 123

b)

It will throw a compilation error

c)

It will assign 0 to number

21.

The program is supposed to calculate the sum of all even numbers from 1 to 10, but the result is wrong.

int sum = 0;

for (int i = 1; i <= 10; i++)

{

if (i % 2 == 1) { sum += i; }

}

Console.WriteLine(sum);

What’s the issue?

a)

The loop condition is correct

b)

The condition should check for even numbers

c)

Missing initialisation of sum

22.

The method below doesn't compile. Why?

public static int GetSquare(int number)

{

if (number > 0)

{

return number * number;

}

}

a)

The method doesn't return a value for all paths

b)

The condition is incorrect

c)

The method should be void