Is it possible in C# to execute a switch case without breaking?
This is an example of a switch where using break in desired
var bar = "Foo";
switch (foo) {
case 0:
case 1:
bar += " Bar";
case 2:
case 3:
Console.WriteLine(bar);
break;
default:
break;
}
This is what the code should produce:
0: Foo Bar
1: Foo Bar
2: Bar
3: Bar
Else: nothing
Is it possible to do this or would I have to do:
var bar = "Foo";
if(foo == 0 || foo == 1) bar += " Bar";
switch (foo) {
case 0:
case 1:
case 2:
case 3:
Console.WriteLine(bar);
break;
default:
break;
}