分页之 skip(pageindex*(index-1).take(size).Tolist();


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倍


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM