为什么不能在接口定义中使用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# ×1