Why does this generic cast fail?

前端 未结 4 944
慢半拍i
慢半拍i 2020-12-18 10:16

I have the following inheritance:

internal abstract class TeraRow{}

internal class xRow : TeraRow {} // xRow is a child of TeraRow

public IEnumerable

        
4条回答
  •  醉梦人生
    2020-12-18 10:37

    You're running afoul of contravariance. You'd need c# 4.0 for that to work. The type IEnumerable can't be exchanged for IEnumerable in 2.0 to 3.5. The msdn article on it is http://blogs.msdn.com/ericlippert/archive/tags/Covariance+and+Contravariance/default.aspx

提交回复
热议问题