wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C# M1 - M2

Total questions: 22

Worksheet time: 9mins

Name
Class
Date
1.

What is the Console.WriteLine() Function do?

a)

Reads Input

b)

Clears the console

c)

Writes to the console with a newline

d)

writes to a file

2.

Which of the following is the correct way to comment out multiple lines in C#?

a)

//--

b)

/* */

c)

__..__

d)

<!-- -->

3.

What is the extension of a C# language file?

a)

.c

b)

.cpp

c)

.cs

d)

.csp

4.

CLR stands for ___.

a)
  1. Common Type System

b)

Java Virtual Machine

c)

Common Language Specification

d)

Common Language Runtime

5.

Which symbols are used to mark the beginning and end of a code block?

a)
  1. Square brackets []

b)
  1. Curly braces {}

c)
  1. Round brackets ()

d)
  1. Double-quotes ""

6.

Every C# statement is terminated by ___.

a)
  1. Colon (:)

b)

  1. Semicolon (;)

c)
  1. Comma (,)

d)
  1. Dot (.)

7.

C# is a programming language, developed by ___.

a)
  1. Oracle

b)

Microsoft

c)

GNU project

d)

Google

8.

What will be the output of the following C# code snippet? ```csharp int a = 5; if (a == 5) { Console.WriteLine("Equal"); } ```

a)

No output

b)

Equal

c)

Error

d)

Not Equal

9.

In C#, which of the following operators is used to check if two values are not equal?

a)

==

b)

!=

c)

>

d)

<

10.

What will be the output of the following C# code snippet? ```csharp int c = 15; if (c > 10) { Console.WriteLine("Greater"); } else { Console.WriteLine("Not Greater"); } ```

a)

Greater

b)

Not Greater

c)

Error

d)

No output

11.

Which of the following C# statements correctly checks if a variable `d` is less than or equal to 20?

a)

if (d < 20)

b)

if (d <= 20)

c)

if (d == 20)

d)

if (d >= 20)

12.

What will be the output of the following C# code snippet? ```csharp int e = 25; if (e < 20) { Console.WriteLine("Less"); } else if (e == 25) { Console.WriteLine("Equal"); } else { Console.WriteLine("Greater"); } ```

a)

Less

b)

Equal

c)

Greater

d)

Error

13.

In a C# switch statement, which keyword is used to exit a case block?

a)

exit

b)

break

c)

continue

d)

stop

14.

What will be the output of the following C# code snippet? ```csharp int f = 3; switch (f) { case 1: Console.WriteLine("One"); break; case 2: Console.WriteLine("Two"); break; case 3: Console.WriteLine("Three"); break; default: Console.WriteLine("Other"); break; } ```

a)

One

b)

Two

c)

Three

d)

Other

15.

Which of the following C# statements correctly checks if a variable `g` is greater than or equal to 50?

a)

if (g > 50)

b)

if (g >= 50)

c)

if (g == 50)

d)

if (g <= 50)

16.

What will be the output of the following C# code snippet? ```csharp int h = 7; if (h > 10) { Console.WriteLine("Greater"); } else if (h < 5) { Console.WriteLine("Less"); } else { Console.WriteLine("Between"); } ```

a)

Greater

b)

Less

c)

Between

d)

Error

17.

In C#, which of the following is the correct syntax for an if-else statement?

a)

if (condition) { } else { }

b)

if (condition) else { }

c)

if (condition) { } else

d)

if (condition) { } else if { }

18.

What will be the output of the following C# code snippet? ```csharp int k = 5; if (k == 5) { Console.WriteLine("Five"); } else { Console.WriteLine("Not Five"); } ```

a)

Five

b)

Not Five

c)

Error

d)

No output

19.

In a C# switch statement, what will happen if there is no `break` statement in a case block?

a)

The program will stop

b)

The next case block will execute

c)

The default case will execute

d)

An error will occur

20.

What will be the output of the following C# code snippet? ```csharp int l = 20; if (l != 20) { Console.WriteLine("Not Equal"); } else { Console.WriteLine("Equal"); } ```

a)

Not Equal

b)

Equal

c)

Error

d)

No output

21.

What is the correct way to declare an integer variable in C#?

a)

`int number = "100";`

b)

`integer number = 100;`

c)

`int number = 100;`

d)

`Int32 number = 100;`

22.

Which of the following is the correct way to output "Hello, World!" to the console in C#?

a)

`Console.WriteLine("Hello, World!");`

b)

`Console.ReadLine("Hello, World!");`

c)

`Console.Print("Hello, World!");`

d)

`Console.WriteText("Hello, World!");`