【发布时间】:2021-10-14 17:08:18
【问题描述】:
我想为List<T> 类型创建一个扩展方法,以便我可以在其中限制、排序和分页我的数据。
到目前为止,我已经创建了一个这样的静态类:
public static class DataTools {
public static List<T> ToPaging(this List<T> list, int PageNumber,int Count,string OrderField,OrderType OrderType) {
return null;
}
}
但我收到一条错误消息,指出 the type or namespace T could not be found 。
当我像这样使我的类通用时:
public static class DataTools<T> {
public static List<T> ToPaging(this List<T> list, int PageNumber,int Count,string OrderField,OrderType OrderType) {
return null;
}
}
这次我收到一条错误消息:extension method must be defined in a non-generic static class。
我不知道该怎么办。我只想创建一个扩展方法来“Page”在将数据发送到前面之前对其进行“分页”。
【问题讨论】:
标签: c# static extension-methods