Ramon Torras

TECHNOLOGY ENTHUSIAST

Switch Statements with Enums

public enum SomeEnum
{
    Value1,
    Value2,
    Value3,
}
 
 
switch (myParam) // is of type SomeValue
{
    case SomeEnum.Value1:
        // Do something
        break;
    case SomeEnum.Value2:
        // Do something
        break;
    case SomeEnum.Value3:
        // Do something
        break;
    default:
        throw new ArgumentException( Unknown enum value found. );
}

Comments are currently closed.