Click or drag to resize

MoreEnumerableZipShortestTFirst, TSecond, TResult Method (IEnumerableTFirst, IEnumerableTSecond, FuncTFirst, TSecond, TResult)

Returns a projection of tuples, where each tuple contains the N-th element from each of the argument sequences. The resulting sequence is as short as the shortest input sequence.

Namespace:  MoreLinq
Assembly:  MoreLinq (in MoreLinq.dll) Version: 3.3.1+b77df70598ab84c28cd43dcf74594024b6d575e1
Syntax
public static IEnumerable<TResult> ZipShortest<TFirst, TSecond, TResult>(
	this IEnumerable<TFirst> first,
	IEnumerable<TSecond> second,
	Func<TFirst, TSecond, TResult> resultSelector
)

Parameters

first
Type: System.Collections.GenericIEnumerableTFirst
The first sequence.
second
Type: System.Collections.GenericIEnumerableTSecond
The second sequence.
resultSelector
Type: SystemFuncTFirst, TSecond, TResult
Function to apply to each pair of elements.

Type Parameters

TFirst
Type of elements in first sequence.
TSecond
Type of elements in second sequence.
TResult
Type of elements in result sequence.

Return Value

Type: IEnumerableTResult
A projection of tuples, where each tuple contains the N-th element from each of the argument sequences.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTFirst. 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

If the input sequences are of different lengths, the result sequence is terminated as soon as the shortest input sequence is exhausted and remainder elements from the longer sequences are never consumed.

This operator uses deferred execution and streams its results.

Examples
var numbers = new[] { 1, 2, 3 };
var letters = new[] { "A", "B", "C", "D" };
var zipped = numbers.ZipShortest(letters, (n, l) => n + l);
The zipped variable, when iterated over, will yield "1A", "2B", "3C", in turn.
See Also