2009-09-04 107 views
12

可能重复:
Which collection for storing unique strings?使用散列表仅存储密钥?

我目前使用字典<字符串,布尔>存储唯一标识符的列表。这些标识符不需要有任何与它们相关的数据 - 我只是使用Dictionary来快速检查重复项。

由于我只需要键和没有值,是一个字典的方式去这里,或者有另一个集合,我不知道这将是更适合?

+0

DUP:http://stackoverflow.com/questions/692853/which-collection-for-storing-unique-strings – tanascius 2009-09-04 12:05:44

+0

应该提到,这是框架2.0。那就是字典吧。也许我可以使用布尔值作为:) – jnylen 2009-09-04 13:45:40

回答

22

.NET 3.5包括HashSet<T>集合类型,这听起来像你想要的。

15
+1

仅在.NET 3.5和更高版本中可用。 – 2009-09-04 12:09:14

+0

@ 0xA3:但是,只需将这两个单音类复制到您的代码中即可轻松在.NET 2.0中使用它们... https://raw.githubusercontent.com/mono/mono/master/mcs/class/System.Core /System.Collections.Generic/HashSet.cs和https://raw.githubusercontent.com/mono/mono/master/mcs/class/corlib/System.Collections/HashPrimeNumbers.cs – 2014-09-25 08:38:30