Sign in to follow this  
osmanb

[.net] Container equivalent to C++ set?

Recommended Posts

I've only been working with C#/.NET for a short time, but I generally find it really easy to use. Every time I've wanted to do something, it took one Google search to turn up something in the standard library. Today, though, I wanted a container that worked like the STL set from C++. For all of the web-pages that brag about how much better the .NET containers are than the STL ones, and how you should never need to write your own, I can't find anything that works like set. I want a collection of values that remains sorted. There doesn't seem to be anything... All of the sorted containers use both keys and values. It seems like I either have to write my own, or do something nasty like: SortedList< MyType, int > At which point I'll simply ignore the value portion and end up using .Keys to do most of my work. Have I overlooked something? Or is there a better solution than my (ab)use of SortedList?

Share this post


Link to post
Share on other sites
I'd be interested in this too. It seems a strange omission.

Share this post


Link to post
Share on other sites
There's nothing quite like it. It should be fairly easy to grab some code for an AVL or RB tree from the net and create an ISet interface for it tough.

Share this post


Link to post
Share on other sites
Thanks for the replies. I just wanted to be sure I hadn't overlooked anything. I checked every container in Collections and the sub-namespaces, but no luck. Anyways, I've simply used one of the dictionary style (Key/Value) containers for now, wrapped in a one-off container that support indexing and enumeration. I might go back later and implement a proper generic Set, but my application is simple enough that this works.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this