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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:32:15+00:00 2026-06-17T11:32:15+00:00

I have a list of values which i am maintaining like this, public enum

  • 0

I have a list of values which i am maintaining like this,

        public enum DisplayUnits
    {
        Vertical = 0,
        Horizontal = 1,
        Track = 2,
        Empty = 3,

    }
    public static string DisplayUnitsImage(DisplayUnits unit)
    {
        switch (unit)
        {
            case DisplayUnits.Vertical:
                return @"/image1";
            case DisplayUnits.Horizontal:
                return @"/image2";
            case DisplayUnits.Track:
                return @"/image3";
            case DisplayUnits.Empty:
                return @"/image4";
            default:
                return @"/image5";
        }

    }
    public static string DisplayUnitID(DisplayUnits unit)
    {
        switch (unit)
        {
            case DisplayUnits.Vertical:
                return @"1234";
            case DisplayUnits.Horizontal:
                return @"1235";
            case DisplayUnits.Track:
                return @"1236";
            case DisplayUnits.Empty:
                return @"1237";
            default:
                return @"1238";
        }
    }

For retrieving the image path i ll call the method by passing the enum.
Can it be written in simpler manner because for adding one value i need to change in three places?
Using of Tuple is recommended in this context?

  • 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-17T11:32:16+00:00Added an answer on June 17, 2026 at 11:32 am

    Let me change my answer completely.

    As soon as you state, that you need to hardcode all possible unitids and images, you may have them stored into an array in your code like:

    static string[] Images = 
    { 
        "/VerticalImage", 
        "/HorizontalImage", 
        "/TrackImage", 
        "/EmptyImage" 
    }; //and so on...
    

    that is the proper image (or unitid) is stored at the position matching relevant DisplayUnits int representation.

    Then you’ll be able to have the desired method work like this:

    public static string DisplayUnitsImage(DisplayUnits unit)
    {
        return string.Concat(Images[(int)unit], (int)unit);
    }
    

    So the only things you’ll need to edit, if the DisplayUnits enum is edited, are

    1. change the enum itself
    2. change each of the arrays containing data (string[] Images in this example)

    You needn’t to edit the bodies of the methods (DisplayUnitsImage, DisplayUnitID, and others if any).

    Or even easier. If all your methods work similarly, that is simply concat the data field and unit representation, then you may have one method instead all of them:

    public static string DisplayUnitsData(string[] data, DisplayUnits unit)
    {
        return string.Concat(data[(int)unit], (int)unit);
    }
    

    and pass the appropriate array (like Images in this example) as data argument:

    string result = DisplayUnitsData(Images, DisplayUnits.Vertical);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of values in my XML file which I would like
So I have this list which uses values from an ArrayList (and I can't
I have a list of items, which has two values, a name and an
I have a ListView which displays a list of string values. I want to
I have a select list which is being populated using the values from a
I have the following select list from which the user can select multiple values.
I have a list or set of values that I would like to know
i have List of int which consists of value 0,0,0,1,2,3,4,0,0 now i like to
I have a list but in this list there are lots of elements which
I have this program which fills a vectors with float values, ensuring each vector

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.