13

Possible Duplicate:
Which collection for storing unique strings?

I am currently using a Dictionary<string, bool> to store a list of unique identifiers. These identifiers do not need to have any data associated with them - I am just using the Dictionary to be able to quickly check for duplicates.

Since I only need keys, and no values, is a Dictionary the way to go here, or is there another collection I don't know about that would be better suited?

Community
  • 1
  • 1
We Are All Monica
  • 13,000
  • 8
  • 46
  • 72

2 Answers2

24

.NET 3.5 includes the HashSet<T> collection type, which sounds like what you want.

Jason
  • 28,040
  • 10
  • 64
  • 64
17

HashSet<T>

Lee
  • 142,018
  • 20
  • 234
  • 287
  • 1
    Which is available in .NET 3.5 and later only. – Dirk Vollmar Sep 04 '09 at 12:09
  • @0xA3: But which you can easily use in .NET 2.0 by just copying these two mono classes into your code... https://raw.githubusercontent.com/mono/mono/master/mcs/class/System.Core/System.Collections.Generic/HashSet.cs and https://raw.githubusercontent.com/mono/mono/master/mcs/class/corlib/System.Collections/HashPrimeNumbers.cs – Stefan Steiger Sep 25 '14 at 08:38