我有一个 interface
interface Repository {
...
List<T> GetAll<T>();
...
}
我应该如何实现该方法?编译器说我不能像下面显示的那样做,因为我返回的不是通用列表
public class EmployeeRepository : Repository {
...
public List<T> GetAll<T>() {
List<Employee> employees = new List<Employee>();
...
return employees;
}
制作Repository
一个通用接口:
interface Repository<T> {
List<T> GetAll();
}
public class EmployeeRepository : Repository<Employee> {
public List<Employee> GetAll() {
List<Employee> employees = new List<Employee>();
return employees;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句