分頁之 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