Returns a sequence resulting from applying a function to each
element in the source sequence and its
predecessor, with the exception of the first element which is
only returned as the predecessor of the second element.
Declaration Syntax
C# | Visual Basic | Visual C++ |
public static IEnumerable<TResult> Pairwise<TSource, TResult>( this IEnumerable<TSource> source, Func<TSource, TSource, TResult> resultSelector )
<ExtensionAttribute> _ Public Shared Function Pairwise(Of TSource, TResult) ( _ source As IEnumerable(Of TSource), _ resultSelector As Func(Of TSource, TSource, TResult) _ ) As IEnumerable(Of TResult)
public: [ExtensionAttribute] generic<typename TSource, typename TResult> static IEnumerable<TResult>^ Pairwise( IEnumerable<TSource>^ source, Func<TSource, TSource, TResult>^ resultSelector )
Generic Template Parameters
- TSource
- The type of the elements of source.
- TResult
- The type of the element of the returned sequence.
Parameters
- source (IEnumerable<(Of <(<'TSource>)>)>)
- The source sequence.
- resultSelector (Func<(Of <(<'TSource, TSource, TResult>)>)>)
- A transform function to apply to each pair of sequence.
Return Value
Returns the resulting sequence.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable<(Of <(<'TSource>)>)>. When you use instance method syntax to call this method, omit the first parameter.
Remarks
This operator uses deferred execution and streams its results.
Examples
Copy | |
---|---|
int[] numbers = { 123, 456, 789 }; IEnumerable<int> result = numbers.Pairwise(5, (a, b) => a + b); |
Assembly: MoreLinq (Module: MoreLinq.dll) Version: 1.0.16006.0 (1.0.16006.1845)