MoreEnumerable.TakeEvery<TSource> Method |
Returns every N-th element of a sequence.
Namespace:
MoreLinq
Assembly:
MoreLinq (in MoreLinq.dll) Version: 3.3.1+b77df70598ab84c28cd43dcf74594024b6d575e1
Syntaxpublic static IEnumerable<TSource> TakeEvery<TSource>(
this IEnumerable<TSource> source,
int step
)
<ExtensionAttribute>
Public Shared Function TakeEvery(Of TSource) (
source As IEnumerable(Of TSource),
step As Integer
) As IEnumerable(Of TSource)
public:
[ExtensionAttribute]
generic<typename TSource>
static IEnumerable<TSource>^ TakeEvery(
IEnumerable<TSource>^ source,
int step
)
[<ExtensionAttribute>]
static member TakeEvery :
source : IEnumerable<'TSource> *
step : int -> IEnumerable<'TSource>
Parameters
- source
- Type: System.Collections.Generic.IEnumerable<TSource>
Source sequence - step
- Type: System.Int32
Number of elements to bypass before returning the next element.
Type Parameters
- TSource
- Type of the source sequence
Return Value
Type:
IEnumerable<TSource>
A sequence with every N-th element of the input sequence.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type
IEnumerable<TSource>. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
Remarks
This operator uses deferred execution and streams its results.
Examplesint[] numbers = { 1, 2, 3, 4, 5 };
var result = numbers.TakeEvery(2);
The
result variable, when iterated over, will yield 1, 3 and 5, in turn.
See Also