小编Lud*_*dek的帖子

为什么在接口定义中无法使用IList <T>而在实现中使用List <T>?

为什么不能在接口定义中使用IList然后使用List实现此属性?我在这里遗漏了什么,或者只是C#编译器不允许这样做?

public interface ICategory
{
    IList<Product> Products { get; }
}

public class Category : ICategory
{
    public List<Product> Products { get { new List<Product>(); } }        
}
Run Code Online (Sandbox Code Playgroud)

编译器说错误82'类别'没有实现接口成员'ICategory.Products'.'Category.Products'无法实现'ICategory.Products',因为它没有匹配的返回类型'System.Collections.Generic.IList'

c#

5
推荐指数
2
解决办法
962
查看次数

标签 统计

c# ×1