MultiSets in the Framework

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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
 
Back
Top