Well that is a different problem. You are declaring variables in a way that is meaningless since they can never really be used anywhere.
Going back to your original... case... I think the real issue is the apparent inconsistent syntax of the switch statement. I think adding the braces kind of brings it a little more in line with the rest of the syntax. But who ever does that :) I suspect it's just a legacy syntax. But, for the most part, I agree it's a bit strange. Keep in mind also that in c#, you can't let a case fall through to the next case. David "If we can hit that bullseye, the rest of the dominoes will fall like a house of cards... checkmate!" -Zapp Brannigan, Futurama On 4 June 2013 13:27, David Burstin <[email protected]> wrote: > Ok. Brackets will create a closed inner scope. But I am ruminating on the > intricacies of switch vs if-else from a language design point of view. If, > instead of adding brackets to the switch, I remove them from the if-else > and use 2 different variables it is now the if-else that doesn't compile: > > if (x == 7) > string foo = "a"; // Invalid embedded statement > else > string bar = "b"; // Invalid embedded statement > > > switch (x) > { > case 7: > string foo = "a"; // No problems > break; > default: > string bar = "b"; // No problems > break; > } > > As I said, it's a philosophical question - maybe better suited for a > Friday. > > >
