I have Dictionary<long, Location> PostalCodes .
While i m adding new elements to this Dictionary I want to make a lookup to this dictionary and if the Location.PostalCode is not in this dictionary, I want to insert it. Otherwise I want to skip it. So , need to know if the PostalCode is already in the Collection. Cant use it as the key.
How to do this?
Thanks.
It sounds like you need another dictionary which does use it as the key – basically a bidirectional map. At least, that’s if you want it to perform well. You could just look through every value in the map, but that would be an O(n) operation.
(Alternatively, if you’re doing this once, just create a
HashSet<Location>for all the locations you’re using. You don’t actually need thelong, by the sounds of it for the purpose of the reverse lookup.)