Using generics in abstract classes

前端 未结 7 1514
眼角桃花
眼角桃花 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 11:14

    You need to specify the type in the abstract class:

    public class AbstractClass<T>
    {
        public int Id { get; set; }
        public int Name { get; set; }
    
        public abstract List<T> Items { get; set; }
    }
    
    public class Container : AbstractClass<Widgets>
    {
        public List<Widgets> Items { get; set; }
    }
    
    0 讨论(0)
提交回复
热议问题