Design .NET – Why SortedDictionary Does Not Implement IReadOnlyDictionary

collectionsdesignnet

The .NET type SortedDictionary<TKey, TValue> does not implement the interface IReadOnlyDictionary<TKey, TValue>, although Dictionary<TKey, TValue> does.

It is trivial to make SortedDictionary implement IReadOnlyDictionary by subclassing it (< 10 LOCs).

But I guess there are good reasons why the framework developers did not do it and that’s why I shouldn’t do it. What are those reasons?

Best Answer

Looking at MSDN today, one can see that the MSDN documentation page for SortedDictionary<TKey, TValue>, SortedDictionary<TKey, TValue> does implement IReadOnlyDictionary<TKey, TValue>.

According to the internet archive, that was not the case on November 14th, 2013.

Given that information, it is likely that it was simply an oversight from Microsoft, fixed in a recent .NET point update.