Skip Method

Method
System.Linq

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


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

Parameters

Name Description
source An IEnumerable<TSource> to return elements from.
count The number of elements to skip before returning the remaining elements.

Returns

An IEnumerable<TSource> that contains the elements that occur after the specified index in the input sequence.

Remarks

Example


using System;
using System.Collections.Generic;
using System.Linq;

public class SkipExample
{
    public static void Main(string[] args)
    {
        List<int> numbers = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

        // Skip the first 3 elements
        IEnumerable<int> remainingNumbers = numbers.Skip(3);

        Console.WriteLine("Original numbers:");
        foreach (var number in numbers)
        {
            Console.Write($"{number} ");
        }
        Console.WriteLine("\n");

        Console.WriteLine("Numbers after skipping the first 3:");
        foreach (var number in remainingNumbers)
        {
            Console.Write($"{number} ");
        }
        // Output: 4 5 6 7 8 9 10
    }
}
            

See Also