wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C#.net test 1

Total questions: 10

Worksheet time: 9mins

Name
Class
Date
1.

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

  1. static void Main(string[] args)

  2. {

  3. int a, b, c, x;

  4. a = 80;

  5. b = 15;

  6. c = 2;

  7. x = a - b / (3 c) ( a + c);

  8. Console.WriteLine(x);

  9. Console.ReadLine();

  10. }

a)

78

b)

-84

c)

80

d)

98

2.

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

m = 5; int y;

y = m++;

y = ++m;

a)

y = 5, m = 6; y = 7, m = 7

b)

y = 6, m = 6; y = 7, m = 6

c)

y = 5, m = 6 ; y = 5, m = 5

d)

y = 5, m = 6; y = 7, m = 8

3.

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

  1. bool a = true;

  2. bool b = false;

  3. a |= b;

  4. Console.WriteLine(a);

  5. Console.ReadLine();

a)

0

b)

1

c)

True

d)

False

4.

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

  1. static void Main(string[] args)

  2. {

  3. int a = 5, b = 10;

  4. if (Convert.ToBoolean(Convert.ToInt32(++a)) || Convert.ToBoolean(Convert.ToInt32(++b))) {

  5. Console.WriteLine(a + "\n" + b);

  6. }

  7. else

  8. Console.WriteLine(" C# ");

  9. }

a)

6 11

b)

6 16

c)

6 12

d)

6 10

5.

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

  1. static void Main(string[] args)

  2. {

  3. char ch = 'p';

  4. switch (ch)

  5. {

  6. case 'p':

  7. Console.WriteLine("coco" + "\t" + Convert.ToInt32(ch));

  8. break;

  9. default:

  10. Console.WriteLine("default");

  11. break;

  12. }

  13. Console.WriteLine("main");

  14. }

a)

coco main

b)

coco 112

c)

coco 112 main

d)

compile time error

6.

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

  1. static void Main(string[] args)

  2. {

  3. int i = 0;

  4. if (i == 0)

  5. {

  6. goto label;

  7. }

  8. label: Console.WriteLine("HI...");

  9. Console.ReadLine();

  10. }

a)

Hi…infinite times

b)

Code runs prints nothing

c)

Hi Hi

d)

Hi…

7.

Which of the following is used to define the member of a class externally?

a)

:

b)

::

c)

#

d)

none of the mentioned

8.

What does the following C# code imply?

cs abc; abc = new cs();

a)

Object creation on class csharp

b)

Create an object of type csharp on heap or on stack depending on the size of object

c)

create a reference c on csharp and an object of type csharp on heap

d)

create an object of type csharp on stack

9.

Which reference modifier is used to define a reference variable?

a)

&

b)

ref

c)

#

d)

$

10.

Which of these can be overloaded?

a)

Constructors

b)

Methods

c)

Both Constructors & Methods

d)

None of the mentioned