ZipShortestExtensionZipShortestT1, T2, T3, TResult(IEnumerableT1, IEnumerableT2, IEnumerableT3, FuncT1, T2, T3, TResult) Method

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.

Definition

Namespace: MoreLinq.Extensions
Assembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
C#
public static IEnumerable<TResult> ZipShortest<T1, T2, T3, TResult>(
	this IEnumerable<T1> first,
	IEnumerable<T2> second,
	IEnumerable<T3> third,
	Func<T1, T2, T3, TResult> resultSelector
)

Parameters

first  IEnumerableT1
First sequence
second  IEnumerableT2
Second sequence
third  IEnumerableT3
Third sequence
resultSelector  FuncT1, T2, T3, TResult
Function to apply to each triplet of elements.

Type Parameters

T1
Type of elements in first sequence.
T2
Type of elements in second sequence.
T3
Type of elements in third sequence.
TResult
Type of elements in result sequence.

Return Value

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 IEnumerableT1. 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.

Example

C#
var numbers = new[] { 1, 2, 3 };
var letters = new[] { "A", "B", "C", "D" };
var chars   = new[] { 'a', 'b', 'c', 'd', 'e' };
var zipped  = numbers.ZipShortest(letters, chars, (n, l, c) => c + n + l);
The zipped variable, when iterated over, will yield "98A", "100B", "102C", in turn.

Exceptions

ArgumentNullExceptionfirst, second, third, or resultSelector is .

See Also