wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Variables

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What is the purpose of reading input from command-line arguments in a C# program?

a)

To get user input when the program starts

b)

To display output on the console

c)

To create a graphical user interface

d)

To connect to a database

2.

Which method is used to convert a value type argument into an integer?

a)

ToInt()

b)

Convert.ToInt32()

c)

String.ToNumber()

d)

ParseInt()

3.

Which keyword is used to define a class in C#?

a)

class

b)

struct

c)

object

d)

method

4.

How do you check if a person is eligible for voting in the provided code?

a)

if (int.Parse(args[1])>18)

b)

if (args[2]=='F')

c)

if (args.Length>0)

d)

if (args[0]>18)

5.

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

a)

const

b)

static

c)

readonly

d)

final

6.

Which statement about readonly is correct?

a)

It must be assigned at compile time

b)

It can be assigned only inside the constructor

c)

It allows modification anywhere

d)

It is same as const

7.

Which method is used to compare the values of two strings in C# for equality?

a)

Equals()

b)

CompareTo()

c)

Match()

d)

Compare()

8.

const float PI = 3.14f;

Console.WriteLine(PI * 2);

a)

6.14

b)

6.28

c)

3.14

d)

compile-error

9.

class A {

public static int count = 1;

}

class Program {

static void Main() {

A.count++;

A.count++;

Console.WriteLine(A.count);

}

}

a)

1

b)

2

c)

3

d)

Runtime error

10.

int x = Convert.ToInt32("15");

int y = int.Parse("5");

Console.WriteLine(x + y);

a)

155

b)

10

c)

20

d)

Error