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
.
views:
48answers:
2
+2
A:
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?
Henk Holterman
2010-06-18 11:00:57
+1
A:
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.
Strilanc
2010-06-18 11:00:58