Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个通用的抽象类Plot<T>。如何定义一个可以接受任何抽象类实现的集合?我尝试了以下方法但没有成功:
Plot<T>
public List<Plot<object>> Plots = new List<Plot<object>>();
public List<Plot<dynamic>> Plots = new List<Plot<dynamic>>();
谢谢。
像这样的情况通常需要创建一个非泛型基类,泛型类从该基类派生:
public abstract class Plot { // Put anything which doesn't need T here } public class Plot<T> : Plot { }
然后你可以创建一个List<Plot>.
List<Plot>