1. 程式人生 > >C#中Skip和Take的用法

C#中Skip和Take的用法

ble 返回 keyword list com tlist result 都是 key

Skip()和Take()方法都是IEnumerable<T> 接口的擴展方法,包括C#中的所有Collections類,如ArrayList,Queue,Stack等等,還有數組和字符串都可以調用這兩個方法。

var testList = new List<int>(); //比如 testList裏面是 1,2,3,4,5,6,7,8,9,10 var result = testList.Skip(5); //返回值就是 6,7,8,9,10; var result = testList.Take(5); //返回值就是 1,2,3,4,5 //搭配使用,一般用來分頁
var result = list.Skip(2).Take(2); //返回值 3,4

C#中Skip和Take的用法