According to the Best Practices section of the MSDN documentation for the System.Enum class:
Do not define an enumeration value solely to mirror the state of the enumeration itself. For example, do not define an enumerated constant that merely marks the end of the enumeration. If you need to determine the last value of the enumeration, check for that value explicitly. In addition, you can perform a range check for the first and last enumerated constant if all values within the range are valid.
If I understand correctly, we shouldn’t declare an enum as follows.
public enum DrawOrder
{
VeryBottom = 0,
Bottom = 1,
Middle = 2,
Top = 3,
Lowest = VeryBottom, //marks a position in the enum
Highest = Top, //marks a position in the enum
}
Why is this considered bad practice?
Because those values may change over time. Suppose you set a property to (using your example)
DrawOrder.Highestand store it in your database/document/other-data-sink.Time passes.
Code Changes.
Your
DrawOrderenum has acquired a few more values and the value in your persisted data is now no longer equal toDrawOrder.Highest. It’s only equal to what everDrawOrder.Highestmapped to at the time the data was persisted.Do you think that this situation might have the possibility of causing problems?