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 7835287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:34:56+00:00 2026-06-02T13:34:56+00:00

I have a simple enum: public enum MyEnum { [Description(Zero)] Zero, [Description(A positive number)]

  • 0

I have a simple enum:

public enum MyEnum
{
    [Description("Zero")]
    Zero,
    [Description("A positive number")]
    Positive,
    [Description("Any integer")]
    AnyInteger,
    [Description("A negative number")]
    Negative,
    [Description("Reserved number")]
    Reserved =2
}

However, running the the following code:

MyEnum temp = MyEnum.AnyInteger;

string en = temp.ToString();

sets the en string to Reserved.

Why does it happens?

Is there is some other way to set the string to the used enum string (in this case AnyInteger)?

  • 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-02T13:34:59+00:00Added an answer on June 2, 2026 at 1:34 pm

    when defining an enum the first value start with 0 and it going up from there unless you define other wise, so in your case it’s:

    public enum MyEnum
            {
                [Description("Zero")]
                Zero, //0
                [Description("A positive number")]
                Positive, //1
                [Description("Any integer")]
                AnyInteger, //2
                [Description("A negative number")]
                Negative, //3
                [Description("Reserved number")]
                Reserved = 2 // it's 2 again
               }
    

    you can define the same value twice (or more) in a enum. the ToString find a name with the same value:

    MyEnum temp=MyEnum.AnyInteger; //temp = 2
    
    string en=temp.ToString(); // return the name of the first name with value 2.
    

    if you insist that “Reserved” should have the value 2, put him in the right place of order. otherwise remove the =2

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

Sidebar

Related Questions

I have the following Enum: Public Enum myEnum As Integer first = &H1 second
I have a bunch of different enums, such as... public enum MyEnum { [Description(Army
Lets say I have a simple Enum called Animal defined as: public enum Animal
I have a flags enum defined like this: [Flags] public enum MyEnum { None
Does any have a more elegant way of doing this? [Flags] public enum SomeFlaggedEnum
I have a simple bean with enum field public class TestBean{ @Pattern(regexp = A|B)
So, say I have a simple enum and a class that uses it: enum
I have a simple class, relevant details below: @PersistenceCapable(identityType = IdentityType.APPLICATION) public class SimpleCategory
I have an enum as public enum Operation { Add = 1, Substract =
This is all asp.net c#. I have an enum public enum ControlSelectionType { NotApplicable

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.