Take the 2-minute tour ×

ReadOnlyCollection<T> supports only reading operations. Why T is not marked with out keyword?

share|improve this question
Classes cannot mark type parameters with in or out. –  Kirk Woll Sep 1 '12 at 0:42
1) the interfaces, such as IList<T>, it implements are not co-variant(apart from IEnumerable<T>) since MS designed them badly in .net 2.0. 2) Classes can't be co-variant. –  CodesInChaos Sep 1 '12 at 0:46
@HansPassant How is that relevant to co-variance? IEnumerable<T> and the new IReadOnly... interfaces don't promise that either, and still they're co-variant. –  CodesInChaos Sep 1 '12 at 0:47
add comment

1 Answer

up vote 5 down vote accepted

ReadOnlyCollection supports only reading operations

It only supports reading because is a base class for a generic read-only collection.

Why T is not marked with out keyword?

out keyword indicates that the parameter is covariant and only interfaces and delegates can be covariant. Note that ReadOnlyCollection<T> implements IEnumerable<T> which is covariant.

share|improve this answer
add comment

Your Answer


