Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

question from:https://stackoverflow.com/questions/23604677/why-doesnt-this-goto-inside-this-switch-work

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
121 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...