KeyValuePair vs. DictionaryEntry [Krzysztof Cwalina]
We discussed a problem with implementation of IEnumerable on Dictionary<K,V>. What type should IEnumerable.GetEnumerator().Current return? KeyValuePair<K,V> or DictionaryEntry? Same for ICollection.CopyTo. Instances of what type should be copied to the array?
We decided the following:
- IEnumerable and ICollection interface implementations will use KeyValuePair<K,V> as the item type.
- IDictionary specific members (GetEnumerator returning IDictionaryEnumerator) will use DictionaryEntry as the item type.
The reason is that we are in a process of making a change where IEnumerator<T> would extend IEnumerator. It would be very strange if walking the hierarchy from Dictionary<K,V>->IEnumerable<T>->IEnumerable we suddenly changed the type of the item returned from enumerators.
Comments
- Anonymous
September 03, 2004
Just curious - why was Dictionary templated as Dictionary<K, V> but DictionaryEntry was replaced by KeyValuePair<K, V>? Wouldn't it make more sense to use DictionaryEntry<K, V>? - Anonymous
September 03, 2004
The comment has been removed