grdView.DataSource = Select().Skip(pageSize * (start - 1)).Take(rows).ToList();
这个分页性能上并不高
下面是我的分页
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
public static IList<T> PaginationDataSource<T>(IList<T> list, int pageIndex, int pageSize, out int totals) { totals = 0; if (pageIndex < 0) throw new ArgumentException( "pageIndex必须大于0" ); if (pageSize <= 0) throw new ArgumentException( "pageSize必须大于0" ); totals = list.Count; int rowBegin = (pageIndex - 1) * pageSize >= totals ? 0 : (pageIndex - 1) * pageSize; int rowEnd = rowBegin + pageSize - 1 >= totals ? totals : rowBegin + pageSize - 1; IList<T> result = new List<T>(); for ( int i = rowBegin; i < rowEnd; i++) { result.Add(list[i]); } return result; } |
经测试
我的方法大概 0.000061
Linq 的 skip take 0.000561
比我的方法 慢10倍