G
Guest
I am new to C# and couldn't figure out the rationale for the error "Control cannot fall through from one case label ('case 2:') to another" in the switch statement in this example
int n = 1
switch (n
case 0
Console.WriteLine("0")
break
case 1
Console.WriteLine("1")
break
case 2
Console.WriteLine("2")
Adding a "break;" for case 2 fixes the problem but I'd have expected the compiler to not expect it since there is no other clause to process after this one. I can understand the error being flagged for case 0, 1 but not for 2
int n = 1
switch (n
case 0
Console.WriteLine("0")
break
case 1
Console.WriteLine("1")
break
case 2
Console.WriteLine("2")
Adding a "break;" for case 2 fixes the problem but I'd have expected the compiler to not expect it since there is no other clause to process after this one. I can understand the error being flagged for case 0, 1 but not for 2