C # Data structure, like a dictionary, but no value

Is there any data structure in C # that looks like a dictionary, but only has a key and doesn't matter. I basically want a list of integers that I can quickly find and see if there is a specific value in the list. Of course, for my current use, the list will not cause any performance problems, but it just is not suitable for the purposes of my code.

+48
c # data-structures
Sep 01 '09 at 17:54
source share
4 answers

Yes, it is called HashSet<T> and is available in version 3.5.NET framework. If you are using .NET version 2.0, you can use the dictionary and set the values ​​to null .

+71
Sep 01 '09 at 17:55
source share

If 3.5 is not an option, you can do something like Dictionary <int, int> and just ignore the value. I did this in 2.0, and I try to set the value in the same way as the key.

+4
Sep 01 '09 at 18:00
source share

If you are not targeting .NET 3.5, Power Collections (open source) also provides an implementation of Set.

+2
01 Sep '09 at 18:18
source share

or use a SortedList where the values ​​must be unique

0
Sep 01 '09 at 18:00
source share



All Articles