Its almost the same as goto example, but with switch :
public int Foo() { switch (false) { case false: goto case false; } }
Not sure if this qualifies as new.
Interestingly, the following will not compile:
public static int Foo(bool b) { switch (b) { case true: case false: goto case false; } }
Obviously, the compiler does not have “knowledge” that the logical can have only two possible values. You should explicitly cover all the “possible” results:
public static int Foo(bool b) { switch (b) { case true: case false: default: goto case true; } }
Or in its simplest form:
public static int Foo(bool b) { switch (b) { default: goto default; } }
Yes ... I'm bored at work today.
source share