Skip method in C#

CsharpProgrammingServer Side Programming

Use the Skip() method in C# to skip number of elements in an array.

Let’s say the following is our array −

int[] arr = { 10, 20, 30, 40, 50 };

To skip the first two elements, use the Skip() method and add argument as 2 −

arr.Skip(2);

Let us see an example −

Example

 Live Demo

using System.IO;
using System;
using System.Linq;
public class Demo {
   public static void Main() {
      int[] arr = { 10, 20, 30, 40, 50 };
      Console.WriteLine("Initial Array...");
      foreach (var res in arr) {
         Console.WriteLine(res);
      }
      // skipping first two elements
      var ele = arr.Skip(2);
      Console.WriteLine("New Array after skipping elements...");
      foreach (var res in ele) {
         Console.WriteLine(res);
      }
   }
}

Output

Initial Array...
10
20
30
40
50
New Array after skipping elements...
30
40
50
raja
Published on 05-Sep-2018 10:59:15
Advertisements