问题描述:

I can enumerate through the entries in a HashTable with

foreach (DictionaryEntry de in ht)

but I want to know what the key is for entry x. Something like:

DictionaryEntry de = ht[0]; // this does NOT return DictionaryEntry - it return the object with key 0

网友答案:

HashTable doesn't work that way.

You'd have to create a second hash table or dictionary that maps the other direction. Otherwise you have to use a foreach, like you did in your question.

相关阅读:
Top