shahjapan
shahjapan

Reputation: 14353

how to fetch DictionaryEntry object from 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.

Upvotes: 0

Views: 2308

Answers (3)

Ahmed
Ahmed

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

AakashM
AakashM

Reputation: 63378

Although DictionaryEntry is the type returned when you iterate a Hashtable, it's not really true that a Hashtable 'contains' DictionaryEntrys. 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

David Hedlund
David Hedlund

Reputation: 129832

I don't know if I'm understanding your question correctly, but couldn't you just use this?

myHashtable[key]

Upvotes: 0

Related Questions