General Questions

Question 6 :

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

char ch = Convert.ToChar ('a' | 'b' | 'c'); 
switch (ch)
{
    case 'A': 
    case 'a':
    Console.WriteLine ("case A | case a");
    break;
    
    case 'B': 
    case 'b':
    Console.WriteLine ("case B | case b");
    break;
    
    case 'C':
    case 'c':
    case 'D':
    case 'd':
    Console.WriteLine ("case D | case d");
    break;
}


A). case A | case a
B). case B | case b
C). case D | case d
D). Compile Error
E). No output
Answer : Option C

Question 7 :

Which of the following can be used to terminate a while loop and transfer control outside the loop?

1. exit while
2. continue
3. exit statement
4. break
5. goto


A). 1, 3
B). 2, 4
C). 3, 5
D). 4, 5
E). None of these
Answer : Option D

Question 8 :

The C#.NET code snippet given below generates ____ numbers series as output?

int i = 1, j = 1, val;
while (i < 25)
{
    Console.Write(j + " ");
    val = i + j;
    j = i;
    i = val;
}


A). Prime
B). Fibonacci
C). Palindrome
D). Odd
E). Even
Answer : Option B

Question 9 :

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

if (age > 18 && no < 11)
a = 25;
1. The condition no < 11 will be evaluated only if age > 18 evaluates to True.
2. The statement a = 25 will get executed if any one condition is True.
3. The condition no < 11 will be evaluated only if age > 18 evaluates to False.
4. The statement a = 25 will get executed if both the conditions are True.
5. && is known as a short circuiting logical operator.


A). 1, 3
B). 2, 5
C). 1, 4, 5
D). 3, 4, 5
E). None of these
Answer : Option C

Question 10 :

Which of the following statements are correct?

1. A switch statement can act on numerical as well as Boolean types.
2. A switch statement can act on characters, strings and enumerations types.
3. We cannot declare variables within a case statement if it is not enclosed by { }.
4. The foreach statement is used to iterate through the collection to get the desired information and should be used to change the contents of the collection to avoid unpredictable side effects.
5. All of the expressions of the for statement are not optional.


A). 1, 2
B). 2, 3
C). 3, 5
D). 4, 5
E). None of these
Answer : Option A