The System.Enum
Type
Consider the example shown in the previous section. Now think about what you would expect to happen when using a ToString
operation on, say, the Color.Red
value. Recall that this operation provides a symbolic name for the enum value in question. However, because there are two enum members with the same value, only one of both symbolic names will be returned. Which one it will be? You can’t tell.
This brings us to another discussion about the use of metadata within the platform. Because the runtime representation of an enum value is nothing but its underlying numeric (integral) value, associating it back to a friendly member name is a bit of an unnatural act that requires the ToString
operation to reach into metadata associated ...
Get C# 4.0 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.