Simply put, Microsoft defined a ReadOnlyCollectionBase, yet did not use it as the base class for ReadOnlyCollection<T> when it clearly sounds that this should have been the way.
Am I missing something here? I mean, was there a good reason to NOT make this class the base class?
Probably because it's not generic and implements ICollection whereas ReadOnlyCollection<T> is generic and implements ICollection<T>. Note that ICollection<T> does not implement ICollection. On that topic:
ICollection<T>seems likeICollection, but it’s actually a very different abstraction. We found thatICollectionwas not very useful. At the same time, we did not have an abstraction that represented an read/write non-indexed collection.ICollection<T>is such abstraction and you could say thatICollectiondoes not have an exact corresponding peer in the generic world;IEnumerable<T>is the closest.
From that same post:
ReadOnlyCollection<T>is a much betterReadOnlyCollectionBase. It’s inSystem.Collections.ObjectModelnamespace.
Effectively, ReadOnlyCollection<T> is ReadOnlyCollectionBase in the generics space.
Note, similarly, that IList<T> does not implement IList.
In general, pre-generics classes do not serve as useful abstractions for generic classes (with the exception of IEnumerable).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With