Mega Code Archive

 
Categories / C# Book / 04 LINQ
 

0377 The Skip operator ignores the first x elements and outputs the rest

using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int[] numbers = { 10, 9, 8, 7, 6 }; IEnumerable<int> lastTwo = numbers.Skip(3); // { 7, 6 } foreach (int i in lastTwo){ Console.WriteLine(i); } } } The output: 7 6