I have this enum:
[Flags]
public enum MyEnum
{
NegativeValue = -1,
Value0 = 0,
Value1 = 2 ^ 1,
Value2 = 2 ^ 2,
Value3 = 2 ^ 3,
Value4 = 2 ^ 4
}
Now I want to use a switch on this enum:
public void SwitchThroughEnum(MyEnum myEnum)
{
switch (myEnum)
{
case MyEnum.NegativeValue:
break;
case MyEnum.Value0:
break;
case MyEnum.Value1:
break;
case MyEnum.Value2:
break;
case MyEnum.Value3:
break;
case MyEnum.Value4:
break;
default:
break;
}
}
But I can't compile this, because Visual Studio tells me that "The switch statement contains multiple cases with the label value '0'". I don't know why it does that.
EDIT: Is there any possibility to create the enum in a way to just use the power of 1, 2 etc? I sometimes have enums with way more then 30 entries, and calculating and writing the numbers is time killing