Reputation: 14353
I know the value of key for my Hashtable, from key how can I obtain the object of DictinaryEntry.
I don't want to Iterate over Hashtable.
Upvotes: 0
Views: 2308
Reputation: 7248
I recommend you to use Dictionary instead of Hashtable as it is a typed Hashtable. For data retreivale
if(myHahtable.ContainsKey(key))
object value = myHahtable[key];
Upvotes: 0
Reputation: 63378
Although DictionaryEntry
is the type returned when you iterate a Hashtable
, it's not really true that a Hashtable
'contains' DictionaryEntry
s. DictionaryEntry
is a value type and so doesn't have an identity. If you want 'a' DictionaryEntry
containing a given key and the matching value, you can make one yourself:
DictionaryEntry de = new DictionaryEntry(key, myHashtable[key]);
Upvotes: 3
Reputation: 129832
I don't know if I'm understanding your question correctly, but couldn't you just use this?
myHashtable[key]
Upvotes: 0