I am curious how is it possible that ReadOnlyDictionary implements IDictionary and ICollection but it does not expose the methods Add(TKey key, TValue value)
ReadOnlyDictionary<object, object> dictionary;
dictionary.Add(null, null); // compilation error
IDictionary<object,object> i;
i = dictionary;
i.Add(null, null);// no compilation error
ReadOnlyDictionary explicitly implements the Add methods (both in generic and non-generic form). Something like this:
void IDictionary.Add(Object key, Object value)
You can call it if you cast it to an IDictionary, but it will throw a NotSupportedException according to MSDN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With