|
-
May 31st, 2011, 12:55 PM
#1
[RESOLVED] Given a value, find all keys with that value in a dictionary(of key, value)
Hi guys,
I have a dictionary(of someType, someOtherType) (the types are immaterial). With a given value, I need to find all the keys that have that value in the dictionary. What I am currently doing is this:
Code:
Dim foundList as New List(of someType)
For each key as someType in myDictionary.Keys
If myDictionary(key) = givenValue Then
foundList.Add(key)
End If
Next
Although it works, I have a strong feeling that it's not optimized (I have to loop thru the whole dictionary.keys collection).
Is there a better way doing it (because I'm targeting .Net 2.0, no LINQ please...)?
Thanks for reading,
Stanav.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|