From time to time, I find myself in a situation where I need a class that mimics the behavior of a mathematical set:
- Elements are unordered
- An element can only appear once
- Sets can interact via Union, Intersect, Difference, IsSubset, IsSuperset, etc.
It's not that writing such a class is particularly hard to do, and in fact, I've done it several times; I just wish that there was a Set<T> class in the Base Class Library (BCL). For that reason, I have employed our own formal feedback channel to suggest this for a future version of the .NET framework. If you also think that this would be a good idea, I suggest that you go vote for Set<T> (you'll need to log in before you can vote). The more votes this suggestion gets, the more likely it is to be implemented.
Before anyone points me to some of the publicly available implementations, I might as well point out that the purpose of this suggestion is to include what I think would be a nice utility class in a readily available place (the BCL). I'm aware that free implementations exist (such as in Wintellect's Power Collections), but typically, I don't want to have to import, manage and deploy a complete third-party library just to implement a bit of logic, and I usually end up using some other collection and tweaking my logic a bit. It's just that, every time I do this, I wish I had a Set<T>.
Update: As was pointed out to me in a comment, there will be a HashSet<T> in Orcas, so voting on Set<T> isn't nessary. It's already coming, it just has a different name 🙂