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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:48:19+00:00 2026-05-24T12:48:19+00:00

I need my enum to return a specific string, but I can’t work out

  • 0

I need my enum to return a specific string, but I can’t work out how to make it return a string with breaks in it without having a method to do the conversion. Is it possible to make LicenseTypes.DISCOUNT_EARLY_ADOPTER return DISCOUNT EARLY-ADOPTER without the helper method?

// All license types
public enum LicenseTypes
{
    DISCOUNT,
    DISCOUNT_EARLY_ADOPTER,
    COMMERCIAL,
    COMMERCIAL_EARLY_ADOPTER
}

// Convert enum to correct string
public static string LicenseTypeToString(LicenseTypes Enum)
{
    if (Enum == LicenseTypes.COMMERCIAL)
        return "COMMERCIAL";
    else if (Enum == LicenseTypes.COMMERCIAL_EARLY_ADOPTER)
        return "COMMERCIAL EARLY-ADOPTER";
    else if (Enum == LicenseTypes.DISCOUNT)
        return "DISCOUNT";
    else if (Enum == LicenseTypes.DISCOUNT_EARLY_ADOPTER)
        return "DISCOUNT EARLY-ADOPTER";
    else
        return "ERROR";
}
  • 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-24T12:48:20+00:00Added an answer on May 24, 2026 at 12:48 pm

    Firstly, a separate option from a helper method is simply to have a Dictionary<LicenseTypes, string> which you populate once. That would probably be the simplest approach, to be honest:

    private static readonly Dictionary<LicenseTypes, string> LicenseDesciptions =
        new Dictionary<LicenseTypes, string> 
    {
        { LicenseTypes.COMMERCIAL, "COMMERCIAL" },
        { LicenseTypes.COMMERCIAL_EARLY_ADOPTER, "COMMERCIAL EARLY-ADOPTER" },
        { LicenseTypes.DOMESTIC, "DOMESTIC" },
        { LicenseTypes.DOMESTIC_EARLY_ADOPTER, "DOMESTIC EARLY-ADOPTER" },
    };
    

    (As noted in comments, another alternative is a switch/case… but I personally prefer this way, as effectively you’ve got a data mapping, so it makes sense to use a data structure rather than an execution flow structure. It also means you can swap out dictionaries for different languages etc if you want.)

    Secondly, one option would be to decorate each enum value with a [Description] attribute (or your own attribute if you want), and find that out with reflection – Unconstrained Melody has an extension method which can do that very easily:

    // Throws ArgumentOutOfRangeException if the licenseType value isn't defined
    // or doesn't have a description.
    string description = licenseType.GetDescription();
    

    Also, following .NET naming conventions it should be:

    public enum LicenseType // Singular as it's not a Flags enum
    {
        Discount,
        DiscountEarlyAdopter,
        Commercial,
        CommercialEarlyAdopter
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a set of enum values, but I need each enum value to
I need to use this enum in my C# application, but it won't let
Is there a way of supplying enum values as method-args in pococapsule without resorting
I need to determine whether the ToString() method of an object will return a
I'd need something like @DefaultInstance(Level.NORMAL) enum Level {NORMAL, FANCY, DEBUGGING} which would make Guice
I need to pass back a enum value in perl, how can I do
I need to re-implement the enum.valueof method of a few of my enumerations so
Have enum with inner fields, kind of map. Now I need to get enum
I need a Generic function to retrieve the name or value of an enum
How come java doesn't allow the following generic return type: public <T extends Enum<T>

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.