Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6189511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:25:37+00:00 2026-05-24T02:25:37+00:00

I often see Simple (non-Flags) Enums declared like this: enum Something { Thingy =

  • 0

I often see Simple (non-Flags) Enums declared like this:

enum Something
{
    Thingy = 1,
    Thangamijig = 2,
    Whatsit = 3
}

Why include the optional numeric values? Is this considered a best practice?

The MSDN guidelines for enum design don’t seem to explain a reason for doing this.

A potential answer just ocurred to me: is it to ensure previously serialized objects containing instances of the enum won’t become invalid or have their meaning changed if the enum were to be modified (say by reordering the values or inserting a new value)?

That seems plausible. Are there other reasons?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:25:38+00:00Added an answer on May 24, 2026 at 2:25 am

    This is very important if you’re going to save these values externally, like a database, and want to map their value back to code.

    If not assigned explicitly, they will be set sequentially at compile time.


    For instance:

    enum Something
    {
        Thingy,
        Thangamijig,
        Whatsit
    }
    

    So Thingy == 0, Thanamijig == 1, Whatsit == 2

    This enum is used and saved to the database for a period of time and then some other developer finds a new use for Something and changes it… poorly:

    enum Something
    {
        Whosits,
        Thingy,
        Thangamijig,
        Whatsit
    }
    

    Now Thingy == 1, Thanamijig == 2, Whatsit == 3 and you no longer have the proper mapping.

    This is just one case where not explicitly defining what each enum value maps to can cause a large problem.


    enum definition on MSDN

    The default underlying type of the enumeration elements is int. By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1. For example:

    enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri};

    In this enumeration, Sat is 0, Sun is 1, Mon is 2, and so forth. Enumerators can have initializers to override the default values. For example:

    enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};

    In this enumeration, the sequence of elements is forced to start from 1 instead of 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often see something like that: something.property|escape something is an object, property is it's
I'm still learning ASP.NET and I often see code like this throughout parts of
I often see code like: Iterator i = list.iterator(); while(i.hasNext()) { ... } but
You often see, on sites like The Daily WTF , examples of overengineered code
Do you often see in API documentation (as in 'javadoc of public functions' for
I quite often see on the Internet various complaints that other peoples examples of
Even nowadays I often see underscores in Java variables and methods. An example are
When I read Django code I often see in models what is called a
In Java, you often see a META-INF folder containing some meta files. What is
I'm not sure what they call the fake shortcuts you often see in Windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.