Skip method in C#


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

Updated on: 22-Jun-2020

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements