Derived List to Base IEnumerable

前端 未结 2 1546
失恋的感觉
失恋的感觉 2021-01-24 15:51

I have the following code that compiles in .NET Framework version 4.0 and above:

public abstract class MyBase { }
public class MyDerived : MyBase { }

public abs         


        
2条回答
  •  無奈伤痛
    2021-01-24 16:07

    It's about covariance and contravariance of collections. Check the following link to get more information.

    Starting with the .NET Framework 4, several generic interfaces have covariant type parameters; for example: IEnumerable, IEnumerator, IQueryable, and IGrouping. All the type parameters of these interfaces are covariant, so the type parameters are used only for the return types of the members.

提交回复
热议问题