Why am I getting “The type parameter must be invariantly valid…” error?

余生颓废 提交于 2019-11-29 10:32:11

You cannot make a covariant ICollection<T>, since it allows you to put Ts 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>.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!