Which collection for storing unique strings?

落爺英雄遲暮 提交于 2019-12-18 20:31:09

问题


I'm looking for a collection just like Dictionary(OF Key, Value) but I don't actually need a key and value. Key itself is enough. So something like Collection(Key). It shouldn't accept duplicate keys.

I've looked up couple of collections in .NET Framework but couldn't find what I want. Currently I'm abusing Dictionary(OF String, String) and setting Value as Nothing all the time.

Shall I just continue abusing Dictionary(OF T,T)?


回答1:


I think what you want is a HashSet<T>.




回答2:


HashSet<T> would work for this. It lets you store a unique set of values, without "abusing" a dictionary.




回答3:


List would be better than Collection as noted in this semi-duplicate question.

A hashset in 3.5 would be better still. What version of .net are you using?



来源:https://stackoverflow.com/questions/692853/which-collection-for-storing-unique-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!