According to the .NET API, the class Dictionary<TKey, TValue> is inherited from ICollection<T>, where T is KeyValuePair<TKey, TValue>. How does the Dictionary<TKey, TValue> class hide some of the methods it inherits from ICollection<T>?
For example:
ICollection<T> has the method ICollection.Add(T item)
but when you use a Dictionary<TKey, TValue> object it doesn’t have that method. You can only use Dictionary<TKey, TValue>.Add(TKey key, TValue value). There is no Dictionary<TKey, TValue>.Add(KeyValuePair<TKey,TValue> kvp) method.
Anyone know why? How are those methods hidden?
That is done by implementing the Interface explicitly and making this implementation private/protected… see
You could always cast the
DictionarytoICollectionand then callAdd– though I wouldn’t do this because I don’t know whether it would work…