2 ms·
I got bit by something like that last year - a previous case above it had some logic without a break. I removed a case that switched on a class that no longer
by tunesmith 11y ago
I got bit by something like that last year - a previous case above it had some logic without a break. I removed a case that switched on a class that no longer existed, but had a break. It was effectively stopping the fallthrough from the case that was a couple of screens above. Stuff broke, and I cursed the no-longer-employed developer that felt the need to be clever two years previous.
Java and PHP allow cases that have logic and no break/return, and it's (strongly) arguable that it's a bug. I think C# doesn't allow that. It allows fall-through, but only if the case is empty.
- to3m 11y agoIn C# you can use `goto' to go to any other case as required - including the one that's next, syntactically speaking. So if you need a fall-through from a non-empty case, you can do that, but you do have to be explicit about it.
- acveilleux 11y agoAnd when you take out the case that is "not needed anymore" the compiler will yell at you. I like it.