wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Elements of a C# program

Total questions: 40

Worksheet time: 28mins

Name
Class
Date
1.

What is the primary IDE recommended for C# development?

a)

NetBeans

b)

Eclipse

c)

Visual Studio

d)

IntelliJ IDEA

2.

Which method in C# is used to print text followed by a newline?

a)

Print()

b)

Output()

c)

WriteLine()

d)

Write()

3.

Which method allows printing without a newline in C#?

a)

WriteLine()

b)

PrintLine()

c)

Write()

d)

Output()

4.

What is the correct syntax for declaring a variable in C#?

a)

type variableName = value;

b)

variableName = type value;

c)

value = type variableName;

d)

type = variableName value;

5.

Which of the following is not a correct data type in C#?

a)

int

b)

float

c)

number

d)

string

6.

What keyword is used to declare a constant variable?

a)

var

b)

let

c)

final

d)

const

7.

What is the output of the following code? int x = 5; Console.WriteLine(x + 5);

a)

5

b)

10

c)

15

d)

20

8.

Which operator is used for addition in C#?

a)

&

b)

+

c)

%

d)

*

9.

How do you write a single-line comment in C#?

a)

//

b)

/*

c)

#

d)

--

10.

Which type of casting is done automatically in C#?

a)

Implicit Casting

b)

Explicit Casting

c)

Dynamic Casting

d)

Static Casting

11.

What does the const keyword do in C#?

a)

Declares a variable that can be modified

b)

Declares a variable that is constant and cannot be changed

c)

Declares a global variable

d)

Declares a temporary variable

12.

Which of these is a logical operator in C#?

a)

==

b)

&&

c)

++

d)

+=

13.

Which method is used to combine text and variables for output in C#?

a)

Concat()

b)

Merge()

c)

+

d)

Join()

14.

What does the following code output? Console.WriteLine("Hello " + "World!");

a)

Hello

b)

Hello World!

c)

HelloWorld!

d)

Error

15.

Which data type is used to store true or false values in C#?

a)

int

b)

boolean

c)

float

d)

string

16.

Which keyword is used to convert data types explicitly in C#?

a)

convert

b)

ToString

c)

casting

d)

Convert

17.

What does the == operator check in C#?

a)

Whether two variables are equal

b)

Whether a variable is less than another

c)

Whether two variables are of the same type

d)

None of the above

18.

Which of the following is an arithmetic operator in C#?

a)

&&

b)

==

c)

/

d)

+=

19.

What is the correct syntax for a multi-line comment in C#?

a)

//

b)

/*

c)
d)

#

20.

What is the result of int a = 10; Console.WriteLine(a * 2);?

a)

12

b)

20

c)

5

d)

10

21.

What is the size of the int data type in C#?

a)

4 bytes

b)

2 bytes

c)

8 bytes

d)

1 byte

22.

Which function would you use to convert a double to int in C#?

a)

int()

b)

Convert.ToInt32()

c)

Convert.ToDouble()

d)

ToString()

23.

What is the purpose of type casting in C#?

a)

To change a variable's type at runtime

b)

To assign a value of one type to another

c)

To compare two variables

d)

To join two strings

24.

Which operator is used to compare two values in C#?

a)

=

b)

==

c)

+=

d)

&

25.

Which is not a valid comparison operator in C#?

a)

!=

b)

>=

c)

<=

d)

==

26.

Name the method used to output text in C# without a newline.

(a)  

27.

What is the keyword used to declare a constant variable in C#?

(a)  

28.

What is the symbol for single-line comments in C#?

(a)  

29.

Name the data type used to store textual data in C#.

(a)  

30.

Which operator is used for logical AND in C#?

(a)  

31.

What does IDE stand for?

(a)  

32.

Which method allows conversion of types, like Convert.ToInt32()

(a)  

33.

What is the output of a comparison operation?

(a)  

34.

What is the default value for an integer variable in C#?

(a)  

35.

What type of casting is for converting data from a smaller to a larger type?

(a)  

36.

What is the result of the expression 5 + 3 * 2 in C#?

(a)  

37.

What is the output of

int x = 10;

Console.WriteLine(x / 4);

(a)  

38.

What is the result of the modulus operation 17 % 5 in C#?

(a)  

39.

What is the value of

int x = 2;

int y = 2;

y++;

x--;

Console.Write(x+y-y*x);

(a)  

40.

What is the output of

Console.WriteLine(10.0 / 4);

(a)