2

Possible Duplicate:
Is there a “Set” data structure in .Net?

Duplicate: this is a duplicate of "Is there a “Set” data structure in .Net?". Please close it as a duplicate and address any further answers to the earlier question.

Is there a generic collection analogous to the STL set<T> template in the .NET framework?

If not, how would you implement a non-ordered collection of unique strings? I suppose I could use Dictionary<string, int> and just use the keys, but that feels kind of smelly.

EDIT: sorry, I should have specified that this is for .NET 2.0

Community
  • 1
  • 1
Ferruccio
  • 98,941
  • 38
  • 226
  • 299

6 Answers6

8

Until .NET3.5, no (don't ask me why it took them so long to get these fundamentals added. (There's still no heap class, afaik. The .NET collection classes are surprisingly lackluster).

In 3.5, you have HashSet<T>. It's more like the TR1 unordered_set than std::set though, in that it's unordered, where std::set uses a tree structure internally.

Of course there are several third-party libraries offering to fix these shortcomings.

I've looked at C5 (as suggested by Pratik) before, but never used it. But it seems to be pretty good quality, and has a Set class.

jalf
  • 243,077
  • 51
  • 345
  • 550
4

I can suggest The C5 Generic Collection Library that has a hash set collection class among many others.

softveda
  • 10,858
  • 6
  • 42
  • 50
1

HashSet Class

Dzmitry Huba
  • 4,493
  • 20
  • 19
1

The answer to your question is YES. Check out the Jeff Richter's amazing Power Collections library for some of the most commonly used STL equivalent collection types for .NET. On an unrelated note he also has a Power Threading library

Abhijeet Patel
  • 6,562
  • 8
  • 50
  • 93
  • You beat me! I deleted my answer pointing at Power Collections. I second Abhijeet in thinking that Power Collections is the library you are looking for. – Eric Schoonover Jul 25 '09 at 18:19
0

You can take a look at the HashSet<T> collection.

Kenan E. K.
  • 13,955
  • 3
  • 43
  • 48
0

Since .net 3.5, there is the HashSet<T> which implements a Set. Not sure if it's totally equal to C++'s set though.

Michael Stum
  • 177,530
  • 117
  • 400
  • 535