IDictionary<TKey, TValue>
inherits from IEnumerable<KeyValuePair<TKey, TValue>>
, but IDictionary
for some reason doesn't inherit from IEnumerable<DictionaryEntry>
. I wonder why? I hate to write this ugly .OfType<DictionaryEntry>()
every time when I need to make a query against an IDictionary
.
Making that change would break every existing implementation of the interface (because they would suddenly be missing some of the methods the interface says they must have).
Furthermore, IDictionary only exists for legacy compatibility from the time before generics. You shouldn't be using it in new code, unless absolutely necessary. If you're actually working with object types, you can use IDictionary<object, object> instead.
Because IDictionary
is an older (pre-generics) interface. Changing it would break existing code. It is a legacy.
So the underlying issue is why are you (still) using IDictionary based classes, and can't you upgrade?
Making that change would break every existing implementation of the interface (because they would suddenly be missing some of the methods the interface says they must have).
Furthermore, IDictionary only exists for legacy compatibility from the time before generics. You shouldn't be using it in new code, unless absolutely necessary. If you're actually working with object types, you can use IDictionary<object, object> instead.
© 2022 - 2024 — McMap. All rights reserved.