Old question
My understanding is that C# has in some sense HashSet
and set
types. I understand what HashSet
is. But why set
is a separate word? Why not every set is HashSet<Object>
?
New question
Why does C# has no generic Set
type, similar to Dictionary
type? From my point of view, I would like to have a set with standard lookup/addition/deletion performance. I wouldn't care much whether it is realized with hashes or something else. So why not make a set class that would actually be implemented as a HashSet
in this version of C# but perhaps somewhat different in a future version?
Or why not at least interface ISet
?
Answer
Learned thanks to everyone who answered below: ICollection
implements a lot of what you'd expect from ISet
. From my point of view, though, ICollection
implements IEnumerable
while sets don't have to be enumerable --- example: set of real numbers between 1 and 2 (even more, sets can be generated dynamically). I agree this is a minor rant, as 'normal programmers' rarely need uncountable sets.
Ok, I think I get it. HashSet
was absolutely meant to be called Set
but the word Set
is reserved in some sense. More specifically, creators of .NET architecture wanted to have a consistent set (sic!) of classes for different languages. This means that every name of the standard class must not coincide with any keyword in the .NET languages. The word Set
, however, is used in VB.NET which is actually case-insensitive (is it?) so unfortunately there is no room for maneuvre there.
Mystery solved :)
Epilogue
The new answer by Alex Y. links to the MSDN page which describes the upcoming .NET 4.0 interface ISet
which behaves pretty much as I thought it should and is implemented by HashedSet
. Happy end.