Click or drag to resize

MoreEnumerablePairwiseTSource, TResult Method

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.

Namespace:  MoreLinq
Assembly:  MoreLinq (in MoreLinq.dll) Version: 2.4.0
Syntax
public static IEnumerable<TResult> Pairwise<TSource, TResult>(
	this IEnumerable<TSource> source,
	Func<TSource, TSource, TResult> resultSelector
)

Parameters

source
Type: System.Collections.GenericIEnumerableTSource
The source sequence.
resultSelector
Type: SystemFuncTSource, TSource, TResult
A transform function to apply to each pair of sequence.

Type Parameters

TSource
The type of the elements of source.
TResult
The type of the element of the returned sequence.

Return Value

Type: IEnumerableTResult
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 IEnumerableTSource. 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.
Examples
int[] numbers = { 123, 456, 789 };
IEnumerable<int> result = numbers.Pairwise((a, b) => a + b);
The result variable, when iterated over, will yield 579 and 1245, in turn.
See Also