Reputation: 8588
I have a generic abstract class Plot<T>
. How can I define a collection that will accept any implementation of the abstract class? I have tried the following approaches without success:
public List<Plot<object>> Plots = new List<Plot<object>>();
public List<Plot<dynamic>> Plots = new List<Plot<dynamic>>();
Thanks.
Upvotes: 1
Views: 80
Reputation: 1500275
Situations like this usually call for creating a non-generic base class, from which the generic class derives:
public abstract class Plot
{
// Put anything which doesn't need T here
}
public class Plot<T> : Plot
{
}
Then you can create a List<Plot>
.
Upvotes: 8