C# Data Structure Like Dictionary But Without A Value

后端 未结 4 1079
不思量自难忘°
不思量自难忘° 2021-02-04 23:05

Is there any data structure in C# that is like a dictionary 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

相关标签:
4条回答
  • 2021-02-04 23:42

    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.

    0 讨论(0)
  • 2021-02-04 23:44

    If you're not targeting .NET 3.5, Power Collections (open source) also provides a Set implementation.

    0 讨论(0)
  • 2021-02-04 23:53

    or use a SortedList where values have to be unique

    0 讨论(0)
  • 2021-02-05 00:01

    If 3.5 is not an option you could do something like Dictionary < int, int > and simply ignore the value. i've done this in 2.0 and i tend to set the value to the same as the key.

    0 讨论(0)
提交回复
热议问题