The key and index based collections are sequenced collections that are accessed either by an integer index or via a key. The key can be any type. Multiple key types are allowed. The example below shows the design pattern, implementers need only implement the methods that are appropriate to their collection. The SortedList class is the default implementation of this pattern.
class <Value>IndexedDictionary implements ICollection { // ICollection public void CopyTo(Array array, int index); //Creates an array of DictionaryEntries IEnumerator IEnumerator.GetEnumerator(); //Enumerates over DictionaryEntries //The return value must be castable to IDictionaryEnumerator //Used directly, the IEnumerator enumerates over the values. public int Count {get;}; public Object SyncRoot {get;}; public boolean IsSynchronized {get;}; public boolean Contains (Object key); public void CopyTo(DictionaryEntry[] array, int index); public IDictionaryEnumerator GetEnumerator (); // Design Pattern static <item> IndexedDictionary Synchronized (<item>IndexedDictionary list); public property ICollection Keys; public property ICollection Values; public virtual void Clear (); public virtual bool ContainsKey (<Key> key); public virtual bool ContainsValue (<Value> value); public virtual <Value> this[<Key> key] {get;}; public virtual <Value> Get[int index] {get;}; public virtual void Remove (<Key> key); public virtual void RemoveAt(int index); public virtual int Add (<Key> key, <Value> value); public virtual void Insert (int index, <Key> Key, <Value> value); public int IndexOf (<item> value); }