Queryable.Zip(Of TFirst, TSecond, TResult) Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Merges two sequences by using the specified predicate function.
Assembly: System.Core (in System.Core.dll)
'Declaration <ExtensionAttribute> _ Public Shared Function Zip(Of TFirst, TSecond, TResult) ( _ source1 As IQueryable(Of TFirst), _ source2 As IEnumerable(Of TSecond), _ resultSelector As Expression(Of Func(Of TFirst, TSecond, TResult)) _ ) As IQueryable(Of TResult)
Type Parameters
- TFirst
The type of the elements of the first input sequence.
- TSecond
The type of the elements of the second input sequence.
- TResult
The type of the elements of the result sequence.
Parameters
- source1
- Type: System.Linq.IQueryable(Of TFirst)
The first sequence to merge.
- source2
- Type: System.Collections.Generic.IEnumerable(Of TSecond)
The second sequence to merge.
- resultSelector
- Type: System.Linq.Expressions.Expression(Of Func(Of TFirst, TSecond, TResult))
A function that specifies how to merge the elements from the two sequences.
Return Value
Type: System.Linq.IQueryable(Of TResult)An IQueryable(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 IQueryable(Of TFirst). When you use instance method syntax to call this method, omit the first parameter.| Exception | Condition |
|---|---|
| ArgumentNullException | source1or source2 is Nothing. |
The Zip(Of TFirst, TSecond, TResult) method generates a MethodCallExpression that represents calling Zip(Of TFirst, TSecond, TResult) itself as a constructed generic method. It then passes the MethodCallExpression to the CreateQuery(Of 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(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.AsQueryable().Zip(words, Function(first, second) first & " " & second)
For Each item In numbersAndWords
outputBlock.Text &= item & vbCrLf
Next
' This code produces the following output:
' 1 one
' 2 two
' 3 three