C#中Skip和Take的用法

时间:2019-04-15 11:11:34   收藏:0   阅读:208

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

原文:https://www.cnblogs.com/innershare/p/10709226.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!