I\'ll attempt to shorten this code example:
public interface IThing
{
//... Stuff
}
public class Thing1 : IThing
{
}
public class Thing2 : IThing
{
You cannot make a covariant ICollection<T>
, since it allows you to put T
s into it.
You can make a covariant read-only collection, a contravariant write-only collection, or an invariant read-write collection.
You can't do both, or it wouldn't be typesafe.
To expand on SLaks answer:
To make your code compile, change the return type of ViewAll
from ICollection<T>
to IEnumerable<T>
.