我具有通用类的基本结构
public class Parent<T> where T : Parent<T>
{
}
public class Child : Parent<Child>
{
}
并且我想要一个列表,以便可以将Child对象放置在此处
List<Parent> parents = new List<Parent>();
在Java中,我只能编写List<? extends Parent>
,并且可以将所有Parent的子类轻松添加到列表中。 C#中是否有其他替代方法?
List<Parent<Child>> list = new List<Parent<Child>>();
list.Add(new Child());