Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

switch statement using an enum

Can you not use a straight enum in a switch statement?

It seems i have to cast it:

    public enum blah
    {
        p,b,s
    }

    public void dosomething(blah h)
    {
        switch (h)  // CANNOT DO THIS?
        {
            case 1:
                break;
            case 2:
                break;
            default:
                break;
        }


        switch ((int)h)  // THIS IS OKAY
        {
            case 1:
                break;
            case 2:
                break;
            default:
                break;
        }

    }

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial