But both returns the middle value - orange"
To clarify: in your enum, Red, Yellow and Orange are exactly the same thing; enums in .NET are simply integers - the name part only applies when:
- writing code
- when parsing a string into an enum value at runtime
- when formatting an enum value to a string at runtime
The order of members (including enum definitions) is explicitly not defined in .NET, so all we have a bunch of integer/name pairs - but conceptually, once you have the enum: it is just an integer, and 1 is 1 is 1, regardless of whether you were originally thinking of Red, Yellow, or Orange. In terms of which will be used when performing string parse/format operations when an enum is overlapped like this: again, that is largely undefined, but you can figure it out with trial and error as long as you acknowledge that this is open to change without warning.
Ultimately, don't do this. Either use different values for each enum member, or use a different metaphor to express your intent here. Perhaps what you really want here is something more like:
public enum Colors
{
[SomeMarker(0)]
DarkGreen, // = 0 implicitly
[SomeMarker(0)]
LightGreen, // = 1 implicitly
[SomeMarker(1)]
Red, // = 2 implicitly
[SomeMarker(1)]
Orange, // = 3 implicitly
[SomeMarker(1)]
Yellow, // = 4 implicitly
[SomeMarker(2)]
Blue, // = 5 implicitly
[SomeMarker(2)]
LightBlue, // = 6 implicitly
[SomeMarker(2)]
Black, // = 7 implicitly
}
Looking up custom attribute values from enums is perfectly possible. So you'd just define your SomeMarkerAttribute : Attribute
.