Something I do often if I’m storing a bunch of string values and I want to be able to find them in O(1) time later is:
foreach (String value in someStringCollection) { someDictionary.Add(value, String.Empty); }
This way, I can comfortably perform constant-time lookups on these string values later on, such as:
if (someDictionary.containsKey(someKey)) { // etc }
However, I feel like I’m cheating by making the value String.Empty. Is there a more appropriate .NET Collection I should be using?
If you’re using .Net 3.5, try HashSet. If you’re not using .Net 3.5, try C5. Otherwise your current method is ok (bool as @leppie suggests is better, or not as @JonSkeet suggests, dun dun dun!).