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

The Archive Base Latest Questions

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

I like to use enum as value holders whereever possible and I like it.

  • 0

I like to use enum as value holders whereever possible and I like it. It is easy to use i.e. just put a dot and see values. It is a good replacement of hard code some time.

But still it has some limitations. We cannot put special characters in values and some other.

Actually I am trying to make code reusable. Please guide me. Is there some technique or way that I can use some data structure like enum that is flexible but have no limitations.

  • 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-24T06:59:39+00:00Added an answer on May 24, 2026 at 6:59 am

    If I cannot use an enum for a set of predefined values, I use a class of static constants. They look much the same in use, but the values can be anything from a decimal to a string to a struct or class. I’ve done this for predefined cell color schemes in GridViews, much like the built-in Color class has predefined constant values. Mathematical and scientific constants such as e and Pi (if you wanted different values than are provided by the Math class), or the acceleration of gravity (9.8m/s2), or the speed of light (299,792,458m/s), can also be specified in this way.

    If you think you can’t use Enums because you need to store predefined string values, try this handy trick using the System.ComponentModel Description attribute:

    public Enum MyStrings
    {
       [Description("This is string one")] StringOne,
       [Description("This is a different string")] StringTwo,
       ...
    }
    

    To get the strings out, you simply examine the Description attribute, the code for which is a little messy but can be easily hidden behind an extension method:

    public static string GetDescription(this Enum enumValue)
        {
            object[] attr = enumValue.GetType().GetField(enumValue.ToString())
                .GetCustomAttributes(typeof (DescriptionAttribute), false);
    
            return (attr.Length > 0) 
                ? ((DescriptionAttribute) attr[0]).Description 
                : String.Empty;            
        }
    

    Usage:

    var stringOne = MyStrings.StringOne.GetDescription(); //"This is string one"
    

    In this case, you can also consider using a Resource file. The value of the string can be changed from outside the scope of the program, without a recompile.

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

Sidebar

Related Questions

Is it possible to use an index integer to obtain an enum value? For
Since enumeration uses integers, what other structure can I use to give me enum-like
I want to use an Enum to represent some selection values. In the /src/groovy
I read somewhere about giving enums default values like so: typedef enum { MarketNavigationTypeNone
I want to use an enum constant for a property value in jackrabbit. However
I have an enum that maps to possible field values in a char(1) field
I am using AdoNetAppender (SQL server) in my asp.net application and would like use
I like to use static functions in C++ as a way to categorize them,
I like to use Emacs' shell mode, but it has a few deficiencies. One
I like to use IPython's zope profile to inspect my Plone instance, but a

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.