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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:23:58+00:00 2026-05-25T13:23:58+00:00

since i can not have space in enum and i am trying to do

  • 0

since i can not have space in enum and i am trying to do something like this but seems like does not like it….

public enum EnumState
{
    NewYork,
    NewMexico
}


public EnumState State
    {
        get
        {
            return EnumState ;
        }
        set
        {
            if (EnumState .ToString() == "NewYork".ToString())
            {
                value = "New York".ToString();
                EnumState = value;
            }
        }
    }
  • 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-25T13:23:59+00:00Added an answer on May 25, 2026 at 1:23 pm

    I have seen this generally handled by putting a [StringValue("New York")] attribute on the enum members. A quick google search returns this blog post, which has a pretty good way of doing it.

    Basically make the attribute class:

    public class StringValueAttribute : Attribute {
    
        public string StringValue { get; protected set; }
    
        public StringValueAttribute(string value) {
            this.StringValue = value;
        }
    }
    

    And an extension method to access it:

       public static string GetStringValue(this Enum value) {
            // Get the type
            Type type = value.GetType();
    
            // Get fieldinfo for this type
            FieldInfo fieldInfo = type.GetField(value.ToString());
    
            // Get the stringvalue attributes
            StringValueAttribute[] attribs = fieldInfo.GetCustomAttributes(
                typeof(StringValueAttribute), false) as StringValueAttribute[];
    
            // Return the first if there was a match, or enum value if no match
            return attribs.Length > 0 ? attribs[0].StringValue : value.ToString();
        }
    

    Then your enum would look like this:

    public enum EnumState{
      [StringValue("New York")]
      NewYork,
      [StringValue("New Mexico")]
      NewMexico,
    }
    

    and you can just use myState.GetStringValue();

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

Sidebar

Related Questions

I'm not duly concerned but can anyone suggest why since installing Visual Studio 2008
This post is incorrectly tagged 'send' since I cannot create new tags. I have
Since DirectedSparseGraph implements serializable ( javadoc ), why can I not create a graph,
Situation: Site with content protected by username/password (not all controlled since they can be
Not in terms of readability, naturally, since you can always arrange the separate methods
So basically I have a layout like this: <div id=header> <div id=elementAbsolute> <div id=headerElement1>
This is what I have so far: public class Numbers { // Fields public
Since I cannot put conditions on elements in a component, I have to separate
I cannot run ['abc'].append( MyModel.objects.all() ) since it generates exception 'NoneType' object is not
Since I can't use Microsoft as an example for best practice since their exception

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.