Take 運算子用於從陣列中傳回給定數量的元素,並且 陣列
Take,從 a 中的第一個元素開始將元素提取到指定位置 sequence.
class Program{ static void Main(string[] args){ List<int> numbers = new List<int> { 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){ List<int> numbers = new List<int> { 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){ List<int> numbers = new List<int> { 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中文網其他相關文章!