Windows Dev Center

Enumerable.Zip(Of TFirst, TSecond, TResult) Method

Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.

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

<ExtensionAttribute> _
Public Shared Function Zip(Of TFirst, TSecond, TResult) ( _
	first As IEnumerable(Of TFirst), _
	second As IEnumerable(Of TSecond), _
	resultSelector As Func(Of TFirst, TSecond, TResult) _
) As IEnumerable(Of TResult)

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.


Type: System.Collections.Generic.IEnumerable(Of TFirst)

The first sequence to merge.

Type: System.Collections.Generic.IEnumerable(Of TSecond)

The second sequence to merge.

Type: System.Func(Of TFirst, TSecond, TResult)

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

Return Value

Type: System.Collections.Generic.IEnumerable(Of TResult)
An IEnumerable(Of T) that contains merged elements of two input sequences.

Usage Note

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


first or second is Nothing.

This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action. The query represented by this method is not executed until the object is enumerated either by calling its GetEnumerator method directly or by using foreach in Visual C# or For Each in Visual Basic.

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 result sequence will have only three elements.

The following code example demonstrates how to use the Zip(Of TFirst, TSecond, TResult) method to merge two sequences.

Dim numbers() As Integer = {1, 2, 3, 4}
Dim words() As String = {"one", "two", "three"}
Dim numbersAndWords = numbers.Zip(words, Function(first, second) first & " " & second)

For Each item In numbersAndWords

' This code produces the following output: 

' 1 one 
' 2 two 
' 3 three

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
© 2015 Microsoft