Is there a class like Dictionary<> in C#, but for just keys, no values?

C#ListDictionaryKey

C# Problem Overview


I guess another way to phrase this would be "Is there a class like List<> in C#, but optimized for checking whether a particular value is present?" I'm sure for a small set of values List<>.Contains would probably be fine, but what if I have a set of thousands or millions of values and wanted to find out whether a certain value was in it?

I've implemented this kind of thing in the past by creating a Dictionary<object, int> and setting the value to 0 for every key, but this feels really clunky. And now there's Stack Overflow, where my stupid question can be transformed into education for thousands (dozens, even). So here it is!

I'm not even sure what such a class would be called, other than maybe Set, so obviously searches on the topic have been... challenging :)

C# Solutions


Solution 1 - C#

Try using the HashSet<T> class.

Edit: I spent a long long time doing exactly what you did until I just stumbled on this class while reading a blog.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChuck WilburView Question on Stackoverflow
Solution 1 - C#JakeView Answer on Stackoverflow