#466 – Explicitly Assigning Only Some Enumerated Values

When defining an enumerated type, you can explicitly assign values to some of the enumerators and let the compiler implicitly assign values to others.

Any enumerated values that you do not explicitly assign a value to will automatically receive a value one greater than the previous value (whether explicitly or implicitly assigned).

For the following enumerated type:

        public enum Moods
        {
            NOMOOD = 0,
            Ambivalent,
            Happy,
            Elated,
            Grouchy = 10,
            Crabby,
            Irate
        }

The Ambivalent enumerator will have a value of 1, Happy will be 2, Elated will be 3, Crabby will be 11 and Irate will be 12.