Tom Knowlton
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;
}
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.