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

  • Home
  • SEARCH
  • 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 9143861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:07:41+00:00 2026-06-17T10:07:41+00:00

The enum I’ve created looks like this: enum MonthOfTheYear : byte { January, February,

  • 0

The enum I’ve created looks like this:

enum MonthOfTheYear : byte
{
    January,
    February,
    March,
    April,
    May,
    June,
    July = 0,
    August,
    September,
    October,
    November,
    December
}

As you can see, July has an initializer of 0.
This has some interesting (side) effects: there seems to be “pairing” of integer values. February ànd August now have values of 1, March ànd September have 2 etc.:

MonthOfTheYear theMonth = MonthOfTheYear.February;
Console.WriteLine(theMonth + " has integer value of " + (int)theMonth);

and

MonthOfTheYear theMonth = MonthOfTheYear.August;
Console.WriteLine(theMonth + " has integer value of " + (int)theMonth);

clearly show this. So far, weird as I find that, I’m willing to go along.
EDIT: I get that assigning July 0 makes the indices start over. I DON’T get why they can co-exist within the same enum.

BUT! IF I then loop through the enum and output all the underlying integer values, weirdness ensues.

MonthOfTheYear theMonth = MonthOfTheYear.January;

for (int i = 0; i < 12; i++)
{
    Console.WriteLine(theMonth + " has integer value of " + (int)theMonth++);
}

outputs

July has integer value of 0
February has integer value of 1
September has integer value of 2
April has integer value of 3
May has integer value of 4
June has integer value of 5
6 has integer value of 6
7 has integer value of 7
8 has integer value of 8
9 has integer value of 9
10 has integer value of 10
11 has integer value of 11

I was hoping someone could explain to me what’s going on behind the scenes, because the integer values are successive, so I’m thinking this is outputting as expected but I’m not seeing it as of yet.

  • 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-06-17T10:07:42+00:00Added an answer on June 17, 2026 at 10:07 am

    http://msdn.microsoft.com/en-us/library/system.enum.getname.aspx

    If multiple enumeration members have the same underlying value, the
    GetName method guarantees that it will return the name of one of those
    enumeration members. However, it does not guarantee that it will
    always return the name of the same enumeration member. As a result,
    when multiple enumeration members have the same value, your
    application code should never depend on the method returning a
    particular member’s name.

    So, to sum it up, when you have multiple members with the same value, the name you get for a particular value is any of the members with that value.

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

Sidebar

Related Questions

I have a enum like this. public enum eTypeVar { Int, Char, Float };
With enum under .net the biggest number you can use is ULong. This mean
I have an enum declared like so: var PlaceType = { PASSABLE_TERRAIN: 1, IMPASSABLE_TERRAIN:
Why is this enum declared in its own file. Is there an advantage to
enum Reaction{single,chain}; class X { X* parent_; X* left_; X* right_; Reaction* reaction_;//this pointer
My enum structure is this public enum UserRole { Administrator = Administrator, Simple_User =
I have an enum in a low level namespace. I'd like to provide a
public enum myEnum { VAL1(10), VAL2(20), VAL3(hai) { public Object getValue() { return this.strVal;
public enum FOO{ TATA(TOTO,TITI); public FOO(BAR bar1,BAR bar2) { bar1.associate(this,bar2); } } public enum
I cant get enum this to work properly on Windows. While compiling on linux

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.