public enum Orientation
{
East = 1,
West = East,
South = 2,
North = 3
}
At this time, East and West has same underlying value (1) and I cannot write a switch like this
switch (orientation)
{
case Orientation.East:
Console.WriteLine("East");
break;
case Orientation.North:
Console.WriteLine("North");
break;
case Orientation.South:
Console.WriteLine("South");
break;
case Orientation.West:
Console.WriteLine("West");
break;
}
Because when I compile, I will have an error: "The label 'case 1:' already occurs in this switch statement"
I don't understand why C# supports to declare enumeration like that. If East and West has same meaning, I will not waste my time to create both of them.
Can anybody has experience with C# help me?
No comments:
Post a Comment