What lines will cause Compile-Time error while compiling the following code given it's a part of some method?
 
int k = 1; 

switch (k)
{ 
    case 0:                                  //1
    case 1: Console.WriteLine("Case 1");     //2 
    case 2:                                   //3 
    default: Console.WriteLine("Default"); //4
 }
 
Explanation
2. Switch statement does not allow a fall through to the next section without goto case or goto default operators. It is required that a break statement or any other control statement (return, throw, continue) is present at the end of each section. Empty sections (like lines 1 and 3) are exceptions to this rule. 4. These rules do also apply to the last section within the switch statement.
C#
C# Quiz
Start Quiz

or Read more about C# Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback