Using generics in abstract classes

前端 未结 7 1517
眼角桃花
眼角桃花 2020-12-05 10:17

I\'m working on an abstract class where the implementing class needs to implement a list of T. The problem is that this doesn\'t work:

public class AbstractC         


        
7条回答
  •  春和景丽
    2020-12-05 10:52

    1. You need to mark AbstractClass abstract, because it contains abstract property

    2. Specify the generic type in the AbstractClass declaration

    3. Implement abstract property with override

    
    public abstract class AbstractClass
    {
        public int Id { get; set; }
        public int Name { get; set; }
    
        public abstract List Items { get; set; }
    }
    
    public class Container : AbstractClass
    {
        public override List Items { get; set; }
    }
    
    

提交回复
热议问题