C# Enumerable Skip

Description

Bypasses a specified number of elements in a sequence and then returns the remaining elements.

Syntax


public static IEnumerable<TSource> Skip<TSource>(
  this IEnumerable<TSource> source,
  int count
)

Parameters

  • TSource - The type of the elements of source.
  • source - An IEnumerable to return elements from.
  • count - The number of elements to skip before returning the remaining elements.

Example

The following code example demonstrates how to use Skip to skip a specified number of elements in a sorted array and return the remaining elements.


/*  w ww. j av  a2s  .  c  o m*/
using System;
using System.Linq;
using System.Collections.Generic;
public class MainClass{
  public static void Main(String[] argv){  
    int[] grades = { 529, 822, 720, 526, 922, 928, 825 };

    IEnumerable<int> lowerGrades =
        grades.OrderByDescending(g => g).Skip(3);

    Console.WriteLine("All grades except the top three are:");
    foreach (int grade in lowerGrades)
    {
        Console.WriteLine(grade);
    }

  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Linq »




Enumerable