If given code is part of some method, which lines will cause compile time error?
 
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.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes