C# Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - General Questions (Q.No. 21)
21.
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;
}
The compiler will report case i and case j as errors since variables cannot be used in cases.
Compiler will report an error since there is no default case in the switch case statement.
The code snippet prints the result as "I am in Case i"".
The code snippet prints the result as "I am in Case j".
There is no error in the code snippet.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
2 comments Page 1 of 1.

Pepe said:   7 years ago
@Div.

That's not true, id, i and j are integers and the switch cases are also using ints.

Div said:   8 years ago
Because id value is integer but in case they are using character so compile time error will come.

Post your comments here:

Your comments will be displayed after verification.