Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

csharp

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which of the following will be the correct output for the C#.NET program given below?

namespace IndiabixConsoleApplication {

class SampleProgram {

static void Main(string[] args) {

int num = 1; funcv(num);

Console.Write(num + ", ");

funcr(ref num); Console.Write(num + ", "); }

static void funcv(int num) {

num = num + 10;

Console.Write(num + ", "); }

static void funcr (ref int num) {

num = num + 10;

Console.Write(num + ", "); } } }

a)
1, 11, 21
b)
11, 11, 21
c)
11, 1, 11
d)
21, 1, 21
2.

What will be the output of the C#.NET code snippet given below?

namespace ConsoleApplication {

class SampleProgram {

static void Main(string[] args) {

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

fun(ref arr); }

static void fun(ref int[] a) {

for (int i = 0; i < a.Length; i++) {

a[i] = a[i] * 5;

Console.Write(a[ i ] + " "); } } } }

a)
5 10 15 20 25
b)
1 2 3 4 5
c)
0 0 0 0 0
d)
10 20 30 40 50
3.

Which of the following are the correct ways to increment the value of variable a by 1?

  1. ++a++;

  2. a += 1;

  3. a ++ 1;

  4. a = a +1;

  5. a = +1;

a)
a++ + 1;
b)
a = a++;
c)
a += 1; a = a + 1;
d)
a = a + 2;
4.

What will be the output of the C#.NET code snippet given below?

byte b1 = 0xF7;

byte b2 = 0xAB;

byte temp;

temp = (byte)(b1 & b2);

Console.Write (temp + " ");

temp = (byte)(b1^b2);

Console.WriteLine(temp);

a)
150 75
b)
163 92
c)
200 100
d)
120 60
5.

What does the following C#.NET code snippet will print?

int i = 0, j = 0;

label: i++;

j+=i;

if (i < 10) {

Console.Write(i +" ");

goto label; }

a)
10 11 12 13 14 15 16 17 18 19
b)
1 2 3 4 5 6 7 8 9
c)
1 2 3 4 5 6 7 8 9 10
d)
0 1 2 3 4 5 6 7 8 9
6.

Which of the following is the correct output for the C#.NET program given below?

int i = 20 ;

for( ; ; ) {

Console.Write(i + " ");

if (i >= -10) i -= 4;

else break; }

a)
20 16 12 8 4 0
b)
20 16 12 8 4 0 -4 -8
c)
20 16 12 8 4
d)
20 16 12 8 4 0 -4
7.

What is the output of the C#.NET code snippet given below?

namespace IndiabixConsoleApplication {

public enum color { red, green, blue };

class SampleProgram {

static void Main (string[ ] args) {

color c = color.blue; switch (c) {

case color.red: Console.WriteLine(color.red);

break;

case color.green: Console.WriteLine(color.green);

break;

case color.blue: Console.WriteLine(color.blue); break; } } } }

a)

red


b)

blue

c)

0

d)

1

8.

If a is an array of 5 integers then which of the following is the correct way to increase its size to 10 elements?

a)

int[] a = new int[5]; int[] a = new int[10];

b)

int[] a = int[5];

int[] a = int[10];

c)

int[] a = new int[5]; a.Length = 10 ;

d)

int[] a = new int[5];

a = new int[10];

9.

Which of the following is the correct output of the C#.NET code snippet given below?

int[ , , ] a = new int[ 3, 2, 3 ]; Console.WriteLine(a.Length);

a)

20

b)

4

c)

18

d)

10

10.

Which of the following statements are correct about the C#.NET code snippet given below?

int[][]intMyArr = new int[2][]; intMyArr[0] = new int[4]{6, 1, 4, 3}; intMyArr[1] = new int[3]{9, 2, 7};

a)

intMyArr is a reference to a 2-D jagged array.

b)

The two rows of the jagged array intMyArr are stored in adjacent memory locations.

c)

intMyArr[0] refers to the zeroth 1-D array and intMyArr[1] refers to the first 1-D array.

d)

intMyArr refers to intMyArr[0] and intMyArr[1].