A Set Collection class

M

Muffin

Does C# have a Set Collection class/functions of some sort? I can not seem
to find it.
A collection that I could extract thing like:

Get only unique entries:
{1,1,1,2,2,3,4,5,5,5,5,6,6} yields {1,2,3,4,5,6}

Get each set of unique entries:
{1,1,1,2,2,3,4,6,6} yields {{1,1,1},{2,2},{3},{4},{5,5,5,5},{6,6}}

Other set operation on a list/collection of objects.

If not what is the way most people do these types of operations. I am a
newbie, so I might need a little spoon feeding at times?

Thx
 
O

Oliver Sturm

Hello Muffin,
Does C# have a Set Collection class/functions of some sort? I can not seem
to find it.

There is none. You can find a number of 3rd party implementations though -
search Google for "c# set" and you'll find a bunch.


Oliver Sturm
 
M

Muffin

Thx
I think I'll try and roll my ourn, I just did not want to reinvent the wheel
with a square one that goes "Thump! Thump! Thump! Thump! Bang!!" every time
I use it ;-).
 
M

Mike Schilling

Chris Mullins said:

Which contains:

C++, C#, Visual Basic .NET, and Java don't provide inherent language
features for working
with sets. If you want to use sets, you need to create your own set
class with the appropriate methods,
properties, and logic.

A strange thing to say, since Java has included a Set interface and a
collection of Set implementations since JDK 1.2. (Not an "inherent language
feature", but there's no need to "create your own".)

In fact, Java implements Sets on top of Maps using a straightforward pattern
that could easily be used in .NET to create a Set on top of Hashtable:

1.Create a Set class that has a field that is a Map.
2. Conceptually, define membership in the Set as being a key in the Map..
3. To add an object O to the Set, add the mapping (O, Map) to the Map.
4. To remove O from the Set, remove that mapping from the Map.
5. To check whether O is in the Set, check whether the Map contains the key
O

etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top