#463 – Enumerated Values Can Be Any Constant Expression
November 28, 2011 Leave a comment
When you define an enum, the individual values can be implicitly defined (one greater than the previous value), assigned to a constant, or assigned to any constant expression.
In the definition of the Moods enumerated type below, constant expressions are used for some of the values.
public const int HappyFactor = 42;
public enum Moods
{
NOMOOD = 0,
Ambivalent = 1,
Crabby = 10,
Grouchy = Crabby - 1,
Happy = HappyFactor,
SuperHappy = 2 * Happy
}