Possible Duplicate:
HashSet replacement in C# 2.0
I am in need of a collection that does not allow duplicates.
In dotNet v4.0 I would use a HashSet
.
What options do I have in dotNet v2.0?
This is the only alternative I can think of for adding without duplicates:
List<Foo> list = new List<Foo>();
if (!list.Contains(newItem)) list.Add(newItem);
But it will be facing much more attemped duplicates than non-duplicates, which makes the O(n)
nature of List.Contains
less than appealing.
What other collection should I use instead? Would a Dictionary<Foo,JunkValue>
be useful?
The collection does not have to be ordered.