I've just found that .NET Fx now has 3 useful interfaces:
And I'm bit confused why HashSet<T>
do not implement IReadOnlyCollection<T>
? Are there any reasons, or Microsoft just forgot about sets again?
UPD
After two-hours googling I've found that there are many collections in BCL which has .Count
property but do not implement IReadOnlyCollection<T>
interface.
UPD2
I've found this post http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/b4fb991a-3f5c-4923-93d4-7cd5c004f859 and the answer by Immo Landwerth where he've said following
Will other collections besides List<> and Dictionary<> be updated to support these interfaces?
Absolutely. In fact, all of our built-in collection types already implement IReadOnlyList<> and IReadOnlyDictionary<>. This means, you can directly pass an instance of List, T[] or Dictionary<> to an API that takes an IReadOnly-version of it.
In version 4.5 of the framework,
HashSet<T>
does not implementIReadOnlyCollection<out T>
.This omission was resolved in version 4.6 of the framework (released almost 12 months after the above question was asked).
These corrections are not limited to
HashSet<T>
, other collections such asStack<T>
andQueue<T>
have received these improvements.Speculation on the reason for any omission is moot. It may be oversight or time pressure but frankly, it is of little consequence. I suspect that even direct input from the Microsoft Development Team would be somewhat subjective, even if we enjoy associated anecdotes.