views:

54

answers:

1

Using .NET 3.5, is there a way to retrieve a value from Hashtable corresponding to the key without iteration?

+3  A: 

var value = hashtable[key]; ?

http://www.c-sharpcorner.com/UploadFile/pradeep.tiwari/PradeepTiwariHashtable11072006072247AM/PradeepTiwariHashtable.aspx

Codebrain
And depending which hash class you're using (System.Collections.Generic.Dictionary) you can use TryGetValue() to avoid an exception if the key doesn't exist.
Dewayne Christensen
Thats correct, don't forget to either use a .TryGetValue() or use .Contains() before attempting to retrieve the value.
Codebrain