EveryNth - Kalkwst/Risotto GitHub Wiki
Returns every nth
element in the sequence.
In this page
Overload | Description |
---|---|
EveryNth(int n) | Returns every nth element in the sequence. |
Returns every nth element in the sequence.
public static IEnumerable<T> EveryNth<T>(this IEnumerable<T> source, int n)
TSource
The type of the elements of source
.
source
IEnumerable <TSource>
The source sequence.
n
Int32
The number of elements to skip before returning an element.
IEnumerable<TSource>
Every nth element in the sequence.
ArgumentNullException
source
is null
ArgumentOutOfRangeException
n
is less than or equal to zero
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 ]