#461 – Enumeration Elements Don’t Need to Be Sequential

Enumeration elements are implicitly set to consecutive integers, starting at 0, as indicated in the comments below.

        // Default type is int
        public enum Mood
        {
            Crabby,      // 0
            Happy,       // 1
            Petulant,    // 2
            Elated       // 3
        };

You can also assign any values you like to the constants.

        public enum Mood
        {
            Crabby = -50,
            Happy = 80,
            Petulant = -20,
            Elated = 99
        };

You can define these constants in any order. They don’t have to be sequential.

        public enum Days
        {
            Friday = 5,
            Monday = 1,
            Saturday = 6,
            Sunday = 0,
            Thursday = 4,
            Tuesday = 2,
            Wednesday = 3
        };
Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: