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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:32:01+00:00 2026-06-01T13:32:01+00:00

In my program I have coded the following private variables and function. private string

  • 0

In my program I have coded the following private variables and function.

    private string _viewName;
    private string _refValue;

    private void getContentDetails(string id) {
        switch (id.Substring(2, 2))
        {
            case "00": _refValue = "14"; _viewName = "Menu"; break;
            case "01": _refValue = "18"; _viewName = "Topic";  break;
            default: _refValue = "00"; _viewName = "Menu"; break;
        }
    }

I am looking for a better way to code this and I was thinking of replacing this with two private functions.

   getViewName(id);
   getRefValue(id);

Can someone suggest what might be the best way that I could code this?

  • 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-01T13:32:03+00:00Added an answer on June 1, 2026 at 1:32 pm

    It’s certainly not wrong to put more than one statement in a switch, but it looks like there could be some duplication here, especially if the needed values that are coupled with an ID are changed.

    It seems to me that you would have to use a map collection object for both viewName and refValue that maps the id’s with the corresponding values. Then use yourCollection.get(id);. That will certainly keep your code best maintainable and consistent.

    Dictionary<string, string> _refValues = new Dictionary<string, string>();
    Dictionary<string, string> _viewNames = new Dictionary<string, string>();
    fillDictionaries();
    
    void fillDictionaries()
    {
        _refValues.add("00","14"); //one way to add a value
        _viewNames["00"] = "Menu"; //another way to add a value
    }
    
    string getRefValue(string id)
    {
        return _refvalues[id]; //there may be a get method but I'm not using an IDE atm
    }
    
    //same function for viewNames
    

    This is not even yet the best solution. The best would be that you use a dictionary to couple the refValues to the viewNames, and then another dictionary that maps the ids to the refvalues. You can then get the refValue by using the id as key, and then the returned refValue as the key to get the viewName. Hope I made myself clear 🙂

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

Sidebar

Related Questions

I have the following code: class Program { static void Main(string[] args) { new
Hello I have the following code namespace ConsoleApplication2 { class Program { static void
I have the following code static void Main(string[] args) { //var source = BlockingMethod();
Consider the following code: class Program { static void Main(string[] args) { Department deathStar
I have the following code : public class MyClass { private readonly string name;
I have the following code: private void button1_Click(object sender, EventArgs e) { Process process
In Unit2 of my program i have the following code: TValue = Record NewValue,
I have the following code in my program: Thread getUsersist, getChatUsers; getUsersList = new
I have the following code: public class Foo {} static class Program { [XmlElement(foo)]
I have a following code in a most inner loop of my program struct

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.