Queryable.Zip<TFirst, TSecond, TResult> Method (IQueryable<TFirst>, IEnumerable<TSecond>, Expression<Func<TFirst, TSecond, TResult>>)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Merges two sequences by using the specified predicate function.

Namespace:   System.Linq
Assembly:  System.Core (in System.Core.dll)

public static IQueryable<TResult> Zip<TFirst, TSecond, TResult>(
	this IQueryable<TFirst> source1,
	IEnumerable<TSecond> source2,
	Expression<Func<TFirst, TSecond, TResult>> resultSelector


Type: System.Linq.IQueryable<TFirst>

The first sequence to merge.

Type: System.Collections.Generic.IEnumerable<TSecond>

The second sequence to merge.

Type: System.Linq.Expressions.Expression<Func<TFirst, TSecond, TResult>>

A function that specifies how to merge the elements from the two sequences.

Return Value

Type: System.Linq.IQueryable<TResult>

An IQueryable<T> that contains merged elements of two input sequences.

Type Parameters


The type of the elements of the first input sequence.


The type of the elements of the second input sequence.


The type of the elements of the result sequence.

Exception Condition

source1or source2 is null.

The Zip<TFirst, TSecond, TResult> method generates a MethodCallExpression that represents calling Zip<TFirst, TSecond, TResult> itself as a constructed generic method. It then passes the MethodCallExpression to the CreateQuery<TElement>(Expression) method of the IQueryProvider represented by the Provider property of the source1 parameter.

The method merges each element of the first sequence with an element that has the same index in the second sequence. If the sequences do not have the same number of elements, the method merges sequences until it reaches the end of one of them. For example, if one sequence has three elements and the other one has four, the resulting sequence will have only three elements.

The following code example demonstrates how to use the Zip<TFirst, TSecond, TResult> method to merge two sequences.

int[] numbers = { 1, 2, 3, 4 };
string[] words = { "one", "two", "three" };

var numbersAndWords = numbers.AsQueryable().Zip(words, (first, second) => first + " " + second);

foreach (var item in numbersAndWords)

// This code produces the following output:

// 1 one
// 2 two
// 3 three

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Available since 4.0
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top