EveryNth - Kalkwst/Risotto GitHub Wiki

Definition

Returns every nth element in the sequence.

In this page

Overloads

Overload Description
EveryNth(int n) Returns every nth element in the sequence.

EveryNth(int n)

Returns every nth element in the sequence.

public static IEnumerable<T> EveryNth<T>(this IEnumerable<T> source, int n)

Type Parameters

TSource
The type of the elements of source.

Parameters

source IEnumerable <TSource>
The source sequence.

n Int32
The number of elements to skip before returning an element.

Returns

IEnumerable<TSource>
Every nth element in the sequence.

Exceptions

ArgumentNullException
source is null

ArgumentOutOfRangeException
n is less than or equal to zero

Example

The following code example demonstrates how to use EveryNth(int n) to get every second element of the sequence.

int[] sequence = new int[] { 1, 2, 3, 4, 5, 6, 7 };

sequence.EveryNth(2);
//=> [ 2, 4, 6 ]
⚠️ **GitHub.com Fallback** ⚠️