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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:35:43+00:00 2026-05-18T10:35:43+00:00

In my application I’ve got some information that can be one of a small

  • 0

In my application I’ve got some information that can be one of a small set of values – so I’d like to use an enum to hold it, ensuring valid values through type-safety at compile time:

public enum Something { A1, A2, A3, B1, B2, C1 };

These enums represent multi-dimensional data (they have a letter and a number in the example above), so I’d like to be able to get the value associated with them, e.g.

Something example = Something.A1;
// Now I want to be able to query the values for example:
example.Letter; // I want to get "A"
example.Number; // "1"I want to get 1

I’ve two possible solutions, neither of them feel very ‘clean’, so I was interested in which people prefer, and why, or whether anyone has any better ideas.

Option 1:
Create a struct which wraps the enum, and provides properties on the wrapped data, e.g.

public struct SomethingWrapper
{
    public Something Value { get; private set; }

    public SomethingWrapper(Something val)
    {
        Value = val;
    }

    public string Letter
    {
        get
        {
            // switch on Value...
        }
    }

    public int Number
    {
        get
        {
            // switch on Value...
        }
    }
}

Option 2:
Leave the enum as it is and create a static Helper class which provides static functions that get the values:

public static class SomethingHelper
{
    public static string Letter(Something val)
    {
        // switch on val parameter
    }

    public static int Number(Something val)
    {
        // switch on val parameter
    }
}

Which should I choose, and why? Or is there a better solution I’ve not thought of?

  • 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-18T10:35:43+00:00Added an answer on May 18, 2026 at 10:35 am

    Third option: like the second option, but with extension methods:

    public static class SomethingHelper
    {
        public static string Letter(this Something val)
        {
            // switch on val parameter
        }
    
        public static int Number(this Something val)
        {
            // switch on val parameter
        }
    }
    

    Then you can do:

    Something x = ...;
    string letter = x.Letter();
    

    It’s unfortunate that there aren’t extension properties, but such is life.

    Alternatively, create your own pseudo enum: something like this:

    public sealed class Something 
    {
        public static Something A1 = new Something("A", 1);
        public static Something A2 = ...;
    
        private Something(string letter, int number)
        {
            Letter = letter;
            Number = number;
        }
    
        public string Letter { get; private set; }
        public int Number { get; private set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Application use NHibernate. I Have object A that contains set of objects B. I
Application-Stack: Rails3, CanCan, Devise, Shoulda I've got some nested Resources and want to test
Application : HTA (therefore IE) This is an application that uses SendKeys to populate
Application[temp] = 8; should set the value 8 to the key temp . However,
Application works fine. I can access everything in debug except for an Array Adapter
My application has one activity which starts two services but does not bind them.
Application Specific Information: com.my-app failed to launch in time Elapsed total CPU time (seconds):
Application stores configuration data in custom section of configuration file. This information is used
Application : I am working on one mid-large size application which will be used
Application I am developing does some kind of server-side authorization. Communication is done via

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.