I am working with Switches and I just am wondering:
Suppose a switch construct has 4 cases and the default. Also suppose the 2nd case is true. If the switch construct does not have a break statement which of the following is true
I am working with Switches and I just am wondering:
Suppose a switch construct has 4 cases and the default. Also suppose the 2nd case is true. If the switch construct does not have a break statement which of the following is true
switch constructs
Chandu Sujay
Hi,
Yep you can't compile if there are no breaks in your case statement. The only exception on this rule if your case statement is empty.
cheers,
Paul June A. Domag
gnesbitt
TonyMoore
Hi,
C# switch doesn't support code fall-through, except when the case is empty. So you need to place breaks in your case if the case contains a code. Example:
switch(myBool) {
case 1:
x = 100;
case 2:
x = 200;
break;
}
The statement above is not permitted.
switch(myBool) {
case 1:
case 2:
x = 200;
break;
}
The statement above is permitted and would cause a fall-through.
cheers,
Paul June A. Domag
Jan Kučera
JavaBoy
Ricardo Francisco