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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:13:30+00:00 2026-06-03T17:13:30+00:00

In my code, I’d like to work with textual names of the items that

  • 0

In my code, I’d like to work with textual names of the items that are coded as one symbol in packets.

In a usual situation, 1012 would mean cat, dog, cat, frog to me, but there are many more pairs like this, so it’s hard to remember all of them. Sometimes they need to be changed, so I thought I should use a Dictionary<string, int> for that purpose. But then…

switch (symbol)
{
    case "0": { /* ... */ }
    case "1": { /* ... */ }
    case "2": { /* ... */ }
    case "n": { /* ... */ }
}

…becomes…

switch (symbol)
{
    case kvpDic["cat"]: { /* ... */ }
    case kvpDic["dog"]: { /* ... */ }
    case kvpDic["frog"]: { /* ... */ }
    case kvpDic["something else"]: { /* ... */ }
}

and the studio says I need to use constants for my switch.

How do I make it work?

Upd: number of such animals and their value pairs are only known at runtime, so the code must not use constants (I guess).

  • 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-03T17:13:33+00:00Added an answer on June 3, 2026 at 5:13 pm

    You could store a Func<T> or Action in the dictionary instead.

    var dict = new Dictionary<int, Action>();
    dict.Add(1, () => doCatThing()); 
    dict.Add(0, () => doDogThing());
    dict.Add(2, () => doFrogThing());
    

    Then, use it like so:

    var action = dict[1];
    action();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code Currently my code looks like that. $stmt = $this->db->prepare(SELECT m.id, m.from_id, m.to_id, m.subject,
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Code for webpage such that if anyone closes it, then next time when he
Code is at: http://jsfiddle.net/m9yen/ Issue: I have multiple LI's listing FOOD ITEMS Each li
Code that was working fine last week is suddenly throwing this exception: System.Data.SqlClient.SqlException (0x80131904):
Code: <div class=container_16 id=enlacesSeo> <div id=titulo_destinos> <h2>PRINCIPALES DESTINOS</h2> </div> <div id=destinos> <ul class=enlacesSeo> <li>Items</li>
code: http://jsfiddle.net/WRppV/4/ I should get something like content=> [141, [203, 206, 204, 205], 142,
Code (Note that the result will not display properly without the images referenced) I'm
Code static void MyClass::ThreadEntryStatic() { //... } void MyClass::Begin() { CreateThread(..,ThreadEntryStatic,..); } In which

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.