Is there any data structure in .NET that is like a Dictionary<TKey,TValue>
but that only has a key and doesn't have a value? I basically want a list of integers that I can quickly lookup and see if a certain value is in the list. Granted, for my current use, a List<int>
would not cause any performance problem, but it just doesn't seem to fit well with the intent of what my code is doing.
Yes, it's called a HashSet<T>
, and available in version 3.5 of the .NET framework. If you use .NET version 2.0, you can use a Dictionary
and set values to null.