Is there a "Set" data structure in .Net?

Ideally, I'm looking for a templated logical Set class. It would have all of the standard set operations such as Union, Intersection, Etc., and collapse duplicated items.

I ended up creating my own set class based on the C# Dictionary<>- just using the Keys.


Solution 1:

HashSet<T> is about the closest you'll get, I think.

Solution 2:

The best set implementation I have seen is part of the wonderful Wintellect's Power Collections: http://www.codeplex.com/PowerCollections.

The set implementation can be found here:
http://www.codeplex.com/PowerCollections/SourceControl/FileView.aspx?itemId=101886&changeSetId=6259
It has all the expected set operations (union, intersect, etc).

Hope this helps!