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.
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.
I don't know if I'm understanding your question correctly, but couldn't you just use this?
myHashtable[key]
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]);
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];