【发布时间】:2010-11-01 19:11:28
【问题描述】:
我有许多 plural item 类,每个类都有一个 singular item 类的集合,如下所示:
public class Contracts : Items
{
public List<Contract> _collection = new List<Contract>();
public List<Contract> Collection
{
get
{
return _collection;
}
}
}
public class Customers: Items
{
public List<Customer> _collection = new List<Customer>();
public List<Customer> Collection
{
get
{
return _collection;
}
}
}
public class Employees: Items
{
public List<Employee> _collection = new List<Employee>();
public List<Employee> Collection
{
get
{
return _collection;
}
}
}
我可以想象我可以使用泛型来把它放到父类中。我怎么能这样做,我想它看起来像这样:
伪代码:
public class Items
{
public List<T> _collection = new List<T>();
public List<T> Collection
{
get
{
return _collection;
}
}
}
【问题讨论】:
标签: c# generics inheritance