Take 运算符用于从数组中返回给定数量的元素,并且 数组
Take,从 a 中的第一个元素开始将元素提取到指定位置 sequence.
class Program{ static void Main(string[] args){ Listnumbers = new List { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 5, 6, 7, 7, 8, 8 }; System.Console.WriteLine(numbers.Count()); var skipRes = numbers.Skip(5); System.Console.WriteLine(skipRes.Count()); Console.ReadLine(); } }
28 23
class Program{ static void Main(string[] args){ Listnumbers = new List { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 5, 6, 7, 7, 8, 8 }; System.Console.WriteLine(numbers.Count()); var takeRes = numbers.Take(5); System.Console.WriteLine(takeRes.Count()); Console.ReadLine(); } }
28 5
class Program{ static void Main(string[] args){ Listnumbers = new List { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 5, 6, 7, 7, 8, 8 }; System.Console.WriteLine(numbers.Count()); var takeSkipRes = numbers.Skip(10).Take(18); System.Console.WriteLine(takeSkipRes.Count()); Console.ReadLine(); } }
28 18
以上是如何在 LINQ C# 中同时使用 Take 和 Skip 运算符?的详细内容。更多信息请关注PHP中文网其他相关文章!