How do I define the return type of an interface method to be another interface?

后端 未结 6 1503
陌清茗
陌清茗 2021-02-02 18:09

I\'m new to interfaces and abstract classes. I want to create a couple of interfaces to define core methods and variables for the objects for a shopping cart system. Then I want

6条回答
  •  粉色の甜心
    2021-02-02 18:50

    You need to user generics in C# 2 to achieve that:

    public interface ICart where T : ICartItem
    {
        // ...
        List CartItems { get; set; }
    }
    
    public abstract class Cart : ICart
    {
        // ...
        public List CartItems { get; set; }
    }
    

提交回复
热议问题