【发布时间】:2018-06-28 16:32:46
【问题描述】:
我有一个基类:
public abstract class Foo<T> where T : TBase { ... }
我还有以下实现 TBase 的类:
public abstract class ImplementsTBase1 : TBase { ... }
public abstract class ImplementsTBase2 : TBase { ... }
我创建了实现这个的新类:
public class Bar1 : Foo<ImplementsTBase1> { ... }
public class Bar2 : Foo<ImplementsTBase2> { ... }
现在我想将这些类的两个实例添加到容器中,如下所示:
public static List<Foo<TBase>> FooList = new List<Foo<TBase>>();
...
FooList.Add(new Bar1());
FooList.Add(new Bar2());
但是,我不能这样做。我能做些什么来实现它?
【问题讨论】:
标签: c# class oop generics inheritance