BagDictionary - Description


The generic class BagDictionary has two type parameters, K - the key type, and T - the data type. BagDictionaries are different from single key dictionaries in that they allow duplicate keys.

When creating a bag dictionary BagDictionary<K,T>, the key class K is expected to be comparable. There are two ways in which the comparer for class K can be specified:

  1. the class K may derive from IComparable of K or
  2. the constructor BagDictionary - Comparer may be used to manually specify the comparer.

The declaration of the bag dictionary class (in C#) is shown below.

[Serializable]
public class BagDictionary<K,T> : IEnumerable<KeyValue<K,T>>,
                                  IEquatable<BagDictionary<K,T>>,
                                  ISerializable
{
 ...
}

When foreach is applied to a bag dictionary, the entries are presented in key order.