Why doesn't this goto inside this switch work?

c#, switch-statement

Solution

This is known bug of the C# compiler when `enum` is typed as `ulong` and you use `goto case` at the same time. If you remove the `ulong` from `enum`, it compiles just fine. And because not many people run into this problem, they are not focusing on fixing it.

Problem

For this program: ``` class Program { static void Main(string[] args) { var state = States.One; switch (state) { case States.One: Console.WriteLine("One"); break; case States.Zero: goto case States.One; } } } public enum States : ulong { Zero = 0, One = 1, } ``` I got: "A switch expression or case label must be a bool, char, string, integral, enum, or corresponding nullable type" But `state` variable is `enum` type. The error disappears if I comment the `goto case` line. I am using VS 2013. + .NET 4.5.1.

Original source

Related problems