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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:50:27+00:00 2026-06-13T12:50:27+00:00

I have a dictionary: Dictionary<ICD_Map2, string> maps = new Dictionary<ICD_Map2, string>(); public class ICD_Map2

  • 0

I have a dictionary:

   Dictionary<ICD_Map2, string> maps = new Dictionary<ICD_Map2, string>();

    public class ICD_Map2
    {
        public string call_type {get; set; }
        public string destination{get; set;} 

    }

maps.Add(new ICD_Map2() {call_type = "Mobile SMS", destination = "Australia"},"Local Text");
maps.Add(new ICD_Map2() {call_type = "Mobile SMS", destination = "International"},"International Text");

So what I want is, when I pass two variables:

Case 1 variable1 = "Mobile SMS" && variable2 = "Australia" I want a function to return "Local Text"

Case 2 "International Text" depending on my input variables matching ICD_Map2 definition "Mobile SMS" and "International".`

How do I construct this mapping function to return the First of the set from a set ofresults (if there are more than one)? This is a very simplified example, I have over 100 mappings.

  • 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-13T12:50:28+00:00Added an answer on June 13, 2026 at 12:50 pm

    To use a dictionary, the key needs to support equality operations. For example:

    public class ICD_Map2 : IEquatable<ICD_Map2>
    {
        public ICD_Map2(string callType, string destination) {
            CallType = callType;
            Destination = destination;
        }
        public override int GetHashCode() {
            int result = 17;
            result = -13 * result +
                (CallType == null ? 0 : CallType.GetHashCode());
            result = -13 * result +
                (Destination == null ? 0 : Destination.GetHashCode());
            return result;
        }
        public override bool Equals(object other) {
            return Equals(other as ICD_Map2);
        }
        public bool Equals(ICD_Map2 other) {
            if(other == null) return false;
            if(other == this) return true;
            return CallType == other.CallType && Destination == other.Destination;
        }
        public string CallType {get; private set; }
        public string Destination{get; private set;} 
    }
    

    Note making it read-only is intentional: mutable keys are going to cause huge problems – avoid that.

    Now you can use this as a key, for example:

    var key = new ICD_Map2("Mobile SMS", "Australia");
    string result;
    if(maps.TryGetValue(key, out result)) {
        Console.WriteLine("found: " + result);
    }
    

    The reverse lookup is problematic, and cannot be optimised unless you have a second dictionary. A simple operation (performance O(n)) would be:

    string result = "International Text";
    var key = (from pair in maps
               where pair.Value == result
               select pair.Key).FirstOrDefault();
    if(key != null) {
        Console.WriteLine("found: " + key);
    }
    

    Putting it all together:

    static void Main()
    {
        Dictionary<ICD_Map2, string> maps = new Dictionary<ICD_Map2, string> {
            {new ICD_Map2 ("Mobile SMS", "Australia"),"Local Text"},
            {new ICD_Map2 ("Mobile SMS", "International"),"International Text"}
        };
    
        // try forwards lookup
        var key = new ICD_Map2("Mobile SMS", "Australia");
        string result;
        if (maps.TryGetValue(key, out result))
        {
            Console.WriteLine("found: " + result);
        }
    
        // try reverse lookup (less efficient)
        result = "International Text";
        key = (from pair in maps
                   where pair.Value == result
                   select pair.Key).FirstOrDefault();
        if (key != null)
        {
            Console.WriteLine("found: " + key);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dictionary public static IDictionary<string, IList<string>> checksCollection = new Dictionary<string, IList<string>>(); I
I have dictionary, like Dictionary<string, bool> accValues = new Dictionary<string, bool>() And I want
i have: Dictionary<string, Dictionary<string, string>> matchesLists = new Dictionary<string, Dictionary<string, string>>(); if (matchesLists.ContainsKey(Errors)) {
I have dictionary which holds my books: Dictionary<string, book> books Book definiton: class book
I have Dictionary from string key i want to get Value of corresponding key
Suppose I have Dictionary like this: Dictionary<string, string> values = new Dictionary<string, string>() {
I have dictionary that is defined as: Dictionary<string, object> d = new Dictionary<string, object>();
I have Dictionary<Guid, DateTime> d = new Dictionary<Guid, DateTime>(); How I can get an
public class Filter { public int A { get; set; } public int B
I have dictionary entries that are read to a Dictionary <string,string> myDict=null; The entries

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.