MultiSets in the Framework

G

Guest

What is the equiverlant of a C++ STL MultiSet in the Framework, as I wish to
register a number of objects with the same Key. The IDictionary class only
seem to support one instance be Key.


Thanks in Advance.
 
C

Chris Taylor

Hi,

Unfortunately there is no corresponding collection in .NET Framework for
std::multiset. Depending on your requirements you might consider using the
Hashtable and storing an ArrayList associated with the key you are adding.
Then if the key already exists add the value to the ArrayList.

The following untested/uncompiled code should give you an idea of what I
mean.

private Hashtable _hash = new Hashtable();
public void Add(object key, object value)
{
ArrayList list = (ArrayList)_hash[key];
if (list == null)
{
list = new ArrayList();
hash[key] = list;
}
list.Add(value);
}

Hope this helps
 

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