adplus-dvertising
frame-decoration

Question

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

int i, j, id = 0; switch (id)
{ 
    case i:
        Console.WriteLine("I am in Case i");
        break; 
    
    case j:
        Console.WriteLine("I am in Case j");
        break;
}

a.

The compiler will report case i and case j as errors since variables cannot be used in cases.

b.

Compiler will report an error since there is no default case in the switch case statement.

c.

The code snippet prints the result as "I am in Case i"".

d.

The code snippet prints the result as "I am in Case j".

Answer: (a).The compiler will report case i and case j as errors since variables cannot be used in cases.

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

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