- Home /
hashtable key or value index?
Hi,
Is it possible to retrieve the index of a key-value pair within a hashtable?
I find odd it's not possible, or is it by design?
I got lost in msdn hashtable description, I am unfortunatly not very good at extracting the info I need from the msdn help just yet...
Is there a better alternative. I need to access a class given a string reference and I need them organize so that I can access them in order, getting the next class.
Thanks for your help,
Jean
Answer by Jean-Fabre · Dec 22, 2011 at 12:27 PM
Yes it is possible, found the answer:
you save the keys into an array, save the values in another array, and then find the index of your key and get the value from the second array of that index.
of course, this is ugly... but that works for my needs.
Answer by _Petroz · Dec 28, 2010 at 09:58 AM
Short answer: No.
Long answer:
http://stackoverflow.com/questions/1848299/how-to-get-the-key-of-a-hashtable-entry ?
The 'index' into a hash table is the key (by definition) since it's an associative container. The concept of an integer index like an array may or may not make sense depending on the hash table implementation. It only makes sense if the hash table uses open addressing but not if it uses seperate chaining (which is more common in my experience).
I thought it would... "Every item is a $$anonymous$$ey/Value pair of format DictionaryEntry"
I actually "need" the index where the key/value is in the hashtable.