D Dave Nov 17, 2004 #1 I know how to get Hashtable value by key, but How can I get Hashtable key by it's value?
D Dennis Myrén Nov 17, 2004 #2 You would have to manually search the table for that value. You could enumerate the table to look for the value, for instance: Hashtable ht...; object value...; IDictionaryEnumerator de = ht.GetEnumerator(); while (de.MoveNext()) { if (value == de.Value) Console.WriteLine(de.Key); }
You would have to manually search the table for that value. You could enumerate the table to look for the value, for instance: Hashtable ht...; object value...; IDictionaryEnumerator de = ht.GetEnumerator(); while (de.MoveNext()) { if (value == de.Value) Console.WriteLine(de.Key); }
J Jon Skeet [C# MVP] Nov 17, 2004 #3 Dave said: I know how to get Hashtable value by key, but How can I get Hashtable key by it's value? Click to expand... You can do it by brute force as Dennis said, but if you're going to have to do this regularly, you should have two Hashtables - one to map one way, and the other to map the other way.
Dave said: I know how to get Hashtable value by key, but How can I get Hashtable key by it's value? Click to expand... You can do it by brute force as Dennis said, but if you're going to have to do this regularly, you should have two Hashtables - one to map one way, and the other to map the other way.
J James Curran Nov 17, 2004 #4 Note, also, that while the key is guaranteed to be unique (points to just one value), the value is not -- several keys could have the same value. -- Truth, James Curran [erstwhile VC++ MVP] Home: www.noveltheory.com Work: www.njtheater.com Blog: www.honestillusion.com Day Job: www.partsearch.com
Note, also, that while the key is guaranteed to be unique (points to just one value), the value is not -- several keys could have the same value. -- Truth, James Curran [erstwhile VC++ MVP] Home: www.noveltheory.com Work: www.njtheater.com Blog: www.honestillusion.com Day Job: www.partsearch.com