C# Program to skip initial elements in an array


If you want to skip a number of elements in an array, then use the Skip() method in C#.

Let’s say the following is our array −

int[] arr = { 24, 40, 55, 62, 70, 82, 89, 93, 98 };

Now to skip first four elements −

var ele = arr.Skip(4);

Let us see the complete example −

Example

 Live Demo

using System.IO;
using System;
using System.Linq;
public class Demo {
   public static void Main() {
      int[] arr = { 24, 40, 55, 62, 70, 82, 89, 93, 98 };
      Console.WriteLine("Initial Array...");
      foreach (var res in arr) {
         Console.WriteLine(res);
      }
      // skipping first four elements
      var ele = arr.Skip(4);
      Console.WriteLine("New Array after skipping elements...");
      foreach (var res in ele) {
         Console.WriteLine(res);
      }
   }
}

Output

Initial Array...
24
40
55
62
70
82
89
93
98
New Array after skipping elements...
70
82
89
93
98

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 22-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements