Why is an IDictionary (not generic) inherited from IEnumerable <DictionaryEntry>?

IDictionary<TKey, TValue> inherits from IEnumerable<KeyValuePair<TKey, TValue>> , but IDictionary for some reason does not inherit from IEnumerable<DictionaryEntry> . I wonder why? I don't like writing this ugly .OfType<DictionaryEntry>() every time I need to make a request against an IDictionary .

+6
generics ienumerable bcl idictionary
source share
2 answers

Performing this change will break all existing implementations of the interface (because they suddenly lacked some of the methods that, according to the interface, should have).

In addition, IDictionary exists only for legacy compatibility from the moment that precedes generics. You should not use it in new code unless absolutely necessary. If you really work with object types, you can use IDictionary <object, object> instead.

+3
source share

Because IDictionary is an older (pre-generics) interface. Changing this would break existing code. This is a legacy.

So, the main problem is why are you still using IDictionary based classes and can you not upgrade?

+4
source share

All Articles