How to do generic polymorphism on open types in C#?
问题 I have an interface like: interface IFoo<in T> { ... } And I want to have a collection of those classes WITHOUT forcing a specific generic parameter for all collection elements, like: class IFooCollection { List<IFoo<?>> _items; public IFooCollection(List<IFoo<?>> items) { _items = items; } ... } 回答1: Since you don't want to force a specific type, make an abstract class or an interface this way: interface IFoo { } And inherit it in your type-specific Foo (with generic parameters), like: