13

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)?

dr. evil
  • 26,944
  • 33
  • 131
  • 201

3 Answers3

25

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

tvanfosson
  • 524,688
  • 99
  • 697
  • 795
2

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

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
2

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?

Community
  • 1
  • 1
Michael Haren
  • 105,752
  • 40
  • 168
  • 205