wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

GAGC-Dotnet-SET2

Total questions: 15

Worksheet time: 22mins

Name
Class
Date
1.

Select the output for the following set of code:

1. static void Main(string[] args)

2. {

3. int y = 5;

4. int x;

5. int k = (!(Convert.ToInt32(y) > 10))? x = y + 3 : x = y + 10;

6. Console.WriteLine(x);

7. Console.WriteLine(y);

8. Console.ReadLine();

9. }

a)

5, 8

b)

8, 5

c)

11, 8

d)

10, 4

2.

Give the Correct Output for the given set of programming code is :

1. class Program

2. {

3. static void Main(string[] args)

4. {

5. int i ;

6. for ( i = 0; i < 5; i++)

7. {

8. int j = 0;

9. j += i;

10. Console. WriteLine(j);

11. }

12. Console. WriteLine(i);

13. Console. ReadLine();

14. }

15. }

a)

0, 1, 2, 3, 4, 5, 6

b)

0, 1, 2, 3, 4

c)

0, 1, 2, 3, 4, 5

d)

0, 1, 2, 3

3.

Select the output for the following set of Code :

1. static void Main(string[] args)

2. {

3. int a = -1;

4. int b = -1;

5. if (Convert.ToBoolean (++a = ++b))

6. Console.WriteLine("a");

7. else

8. Console.WriteLine("b");

9. Console.ReadLine();

10. }

a)

a

b)

b

c)

Compile time error

d)

Code execute successfully with no output

4.

1. static void Main(string[] args)

2. {

3. int x;

4. x = Convert.ToInt32(Console.ReadLine());

5. int c = 1;

6. while (c <= x)

7. {

8. if (c % 2 == 0)

9. {

10. Console.WriteLine("Execute While " + c + "\t" + "time");

11. }

12. c++;

13. }

14. Console.ReadLine();

15. }

for x = 8 the program output will be,

a)

Execute while 1 time Execute while 3 time Execute while 5 time Execute while 7 time

b)

Execute while 2 time Execute while 4 time Execute while 6 time Execute while 8 time

c)

Execute while 1 time Execute while 2 time Execute while 3 time Execute while 4 time Execute while 5 time Execute while 6 time Execute while 7 time

d)

Execute while 2 time Execute while 3 time Execute while 4 time Execute while 5 time

5.

Select the output for the following set of code :

1. static void Main(string[] args)

2. {

3. int i = 0;

4. int j = 0;

5. for (i = 0; i < 4; i++)

6. {

7. for (j = 0; j < 3; j++)

8. {

9. if (i > 1)

10. continue;

11. Console.WriteLine("Hi \n");

12. }

13. }

14. Console.ReadLine();

15. }

a)

Prints hi 4 times

b)

Prints hi 3 times

c)

Prints hi 6 times

d)

Prints hi infinite times

6.

Select the output for the following set of code :

1. class sample

2. {

3. public int i;

4. public int j;

5. public void fun(int i, int j)

6. {

7. this.i = i;

8. this.j = j;

9. }

10. }

11. class Program

12. {

13. static void Main(string[] args)

14. {

15. sample s = new sample();

16. s.i = 1;

17. s.j = 2;

18. s.fun(s.i, s.j);

19. Console.WriteLine(s.i + " " + s.j);

20. Console.ReadLine();

21. }

22. }

a)

Error while calling s.fun() due to inaccessible level

b)

Error as ‘this’ reference would not be able to call ‘i’ and ‘j’

c)

1 2

d)

Runs successfully but prints nothing

7.

Select the correct output for the following code

1. class z

2. {

3. public int X;

4. public int Y;

5. public const int c1 = 5;

6. public const int c2 = c1 * 25;

7. public void set(int a, int b)

8. {

9. X = a;

10. Y = b;

11. }

12.

13. }

14. class Program

15. {

16. static void Main(string[] args)

17. {

18. z s = new z();

19. s.set(10, 20);

20. Console.WriteLine(s.X + " " + s.Y);

21. Console.WriteLine(z.c1 + " " + z.c2);

22. Console.ReadLine();

23. }

24. }

a)

10 20 5 25

b)

20 10 25 5

c)

10 20 5 125

d)

20 10 125 5

8.

The output of code is ?

1. class test

2. {

3. public void print()

4. {

5. Console.WriteLine("Csharp:");

6. }

7. }

8. class Program

9. {

10. static void Main(string[] args)

11. {

12. test t;

13. t.print();

14. Console.ReadLine();

15. }

16. }

a)

Code runs successfully prints nothing

b)

Code runs and prints “Csharp”

c)

None of the mentioned

d)

Syntax error as t is unassigned variable which is never used

9.

What is output for the following set of code?

1. static void Main(string[] args)

2. {

3. string s1 = "Hello";

4. string s2 = "hello";

5. if (s1 == s2)

6. Console.WriteLine("Equal");

7. else

8. Console.WriteLine("Unequal");

9. if (s1.Equals (s2))

10. Console.WriteLine("Equal");

11. else

12. Console.WriteLine("Unequal");

13. Console.ReadLine();

14. }

a)

Equal Unequal

b)

compiler error

c)

Equal Equal

d)

Unequal Unequal

10.

Which of the following statements are correct?

a)

String is value type

b)

String literals can contain any character literal including escape sequences

c)

The equality operators are defined to compare values of string objects as well as references

d)

All of the mentioned

11.

What is output of the following set of code?

1. static void Main(string[] args)

2. {

3. Program p = new Program();

4. p.display(2, 3, 8);

5. int []a = { 2, 56, 78, 66 };

6. Console.WriteLine("example of array");

7. Console.WriteLine("elements added are");

8. p.display(a);

9. Console.ReadLine();

10. }

11. public void display(params int[] b)

12. {

13. foreach (int i in b)

14. {

15. Console.WriteLine("ARRAY IS HAVING:{0}", i);

16. }

17. }

a)

Compile time error

b)

Run time error

c)

Code runs successfully but prints nothing

d)

Code runs successfully and prints given on console

12.

Choose selective differences between an array in c# and array in other programming languages.

a)

Declaring array in C# the square bracket([]) comes after the type but not after identifier

b)

It is necessary to declare size of an array with its type

c)

No difference between declaration of array in c# as well as as in other programming languages

d)

All of the mentioned

13.

What will be the correct output for the given code snippet?

1. class recursion

2. {

3. int fact(int n)

4. {

5. int result;

6. if (n == 1)

7. return 1;

8. result = fact(n - 1) * n;

9. return result;

10. }

11. }

12. class Program

13. {

14. public static void main(String args[])

15. {

16. recursion obj = new recursion() ;

17. Console.WriteLine(obj.fact(4));

18. }

19. }

a)

24

b)

30

c)

120

d)

144

14.

What will be the correct output the for the given code snippet?

1. class maths

2. {

3. int fact(int n)

4. {

5. int result;

6. if (n == 1)

7. return 1;

8. result = fact(n - 1) * n;

9. return result;

10. }

11. }

12. class Output

13. {

14. static void main(String args[])

15. {

16. maths obj = new maths() ;

17. Console.WriteLine(obj.fact(1));

18. }

19. }

a)

2

b)

10

c)

1

d)

0

15.

What will be the correct output for the given code snippet?

1. class maths

2. {

3. int fact(int n)

4. {

5. int result;

6. if (n == 1)

7. return 1;

8. result = fact(n - 1) n;

9. return result;

10. }

11. }

12. class Output 1

3. {

14. static void main(String args[])

15. {

16. maths obj = new maths() ;

17. Console.WriteLine(obj.fact(4)obj.fact(2));

18. }

19. }

a)

64

b)

60

c)

120

d)

48