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: 3.2.0+5205ea241d72b079436060d330cd5c2eae7cdcdf
public static IEnumerable<TResult> Pairwise<TSource, TResult>(
	this IEnumerable<TSource> source,
	Func<TSource, TSource, TResult> resultSelector


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

Type Parameters

The type of the elements of source.
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).
This operator uses deferred execution and streams its results.
var source = new[] { "a", "b", "c", "d" };
var result = source.Pairwise((a, b) => a + b);
The result variable, when iterated over, will yield "ab", "bc" and "cd", in turn.
See Also