-1

Lets say I have the following hashtable:

key value
1 a
2 b
3 c
.. ..
.. ..
26 z

I have a list of char and I have to do a check for each character to see if matches with a Value from the hashtable, if does match, I need to get the correspondent key for

My idea is something like this:

foreach (char c in common_items)
        {
            foreach (DictionaryEntry de in hashtable)
            {
                if (!de.Value.Equals(c))
                {                        
                    Console.WriteLine(de.Key);
                }
            }
        }

I have done research and I could not find anything similar.

Any help is very appreciated. Thanks.

Daniel
  • 145
  • 1
  • 1
  • 6
  • There is `Hashtable` class. – i486 Aug 13 '23 at 10:32
  • Does this answer your question? [Get dictionary key by value](https://stackoverflow.com/questions/2444033/get-dictionary-key-by-value) – Progman Aug 13 '23 at 10:35
  • When I need to do this, assuming that each Value should only be present once, then at the same time as creating the `Hashtable`, I create a reverse one, (transposing values and keys). Then I have a very fast means to find the key for any value – Jonathan Willcock Aug 13 '23 at 10:37
  • 1
    You are using `!de.Value.Equals(c)` in your code & you said "if does match, I need to get the correspondent key". So you want to check for Equals or Not Equals? – HarrY Aug 13 '23 at 11:09
  • What type does `value` have? `char` or `string`? I suppose it's a string. Then `c.ToString()` will help you: `de.Equals(c.ToString())` – Alexander Petrov Aug 13 '23 at 11:11
  • Thanks to everyone who replied. Specially to Harry and Alexander your replies got me where I wanted. – Daniel Aug 13 '23 at 20:09

0 Answers0