vb.net - How to search by key in hashset? -


i wanted collection contain bunch of unique strings. hashset seemed best option since removes duplicates , quick it.

however how go finding item in hash set? loop through elements wouldn't defeat purpose of being hashset? want dictionary key value.

hashsets not used searching. used treat collection whole. can use mathematical sets used for: create unions, intersections, or checks of duplication etc.

the dictionaries , hashsets similar in internal implementation, since based on hashtables. sets not have keys, since not allowed lookup of elements. must use dictionary it. if want ask set element, have enumerate thru them all.

in same way, should not use queues, stacks or linked list looking element.

to have strings in dictionary can use like:

idictionary<string, string dictionary =     new dictionary<string, string>(); dictionary.add("foo", "foo"); dictionary.add("bar", "bar"); string stringthatilookfor = null; if (dictionary.trygetvalue("bar", out stringthatilookfor)) {     // use stringthatilookfor, has value bar  } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -