Queryable.Zip Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
Zip<TFirst,TSecond,TResult>(IQueryable<TFirst>, IEnumerable<TSecond>, Expression<Func<TFirst,TSecond,TResult>>) |
Merges two sequences by using the specified predicate function. |
Zip<TFirst,TSecond,TThird>(IQueryable<TFirst>, IEnumerable<TSecond>, IEnumerable<TThird>) |
Produces a sequence of tuples with elements from the three specified sequences. |
Zip<TFirst,TSecond>(IQueryable<TFirst>, IEnumerable<TSecond>) |
Produces a sequence of tuples with elements from the two specified sequences. |
Zip<TFirst,TSecond,TResult>(IQueryable<TFirst>, IEnumerable<TSecond>, Expression<Func<TFirst,TSecond,TResult>>)
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
Merges two sequences by using the specified predicate function.
public:
generic <typename TFirst, typename TSecond, typename TResult>
[System::Runtime::CompilerServices::Extension]
static System::Linq::IQueryable<TResult> ^ Zip(System::Linq::IQueryable<TFirst> ^ source1, System::Collections::Generic::IEnumerable<TSecond> ^ source2, System::Linq::Expressions::Expression<Func<TFirst, TSecond, TResult> ^> ^ resultSelector);
public static System.Linq.IQueryable<TResult> Zip<TFirst,TSecond,TResult> (this System.Linq.IQueryable<TFirst> source1, System.Collections.Generic.IEnumerable<TSecond> source2, System.Linq.Expressions.Expression<Func<TFirst,TSecond,TResult>> resultSelector);
static member Zip : System.Linq.IQueryable<'First> * seq<'Second> * System.Linq.Expressions.Expression<Func<'First, 'Second, 'Result>> -> System.Linq.IQueryable<'Result>
<Extension()>
Public 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
- IQueryable<TFirst>
The first sequence to merge.
- source2
- IEnumerable<TSecond>
The second sequence to merge.
- resultSelector
- Expression<Func<TFirst,TSecond,TResult>>
A function that specifies how to merge the elements from the two sequences.
Returns
An IQueryable<T> that contains merged elements of two input sequences.
Exceptions
source1
or source2
is null
.
Examples
The following code example demonstrates how to use the Zip 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)
Console.WriteLine(item);
// This code produces the following output:
// 1 one
// 2 two
// 3 three
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
Console.WriteLine(item)
Next
' This code produces the following output:
' 1 one
' 2 two
' 3 three
Remarks
The Zip method generates a MethodCallExpression that represents calling Zip 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.
Applies to
Zip<TFirst,TSecond,TThird>(IQueryable<TFirst>, IEnumerable<TSecond>, IEnumerable<TThird>)
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
Produces a sequence of tuples with elements from the three specified sequences.
public:
generic <typename TFirst, typename TSecond, typename TThird>
[System::Runtime::CompilerServices::Extension]
static System::Linq::IQueryable<ValueTuple<TFirst, TSecond, TThird>> ^ Zip(System::Linq::IQueryable<TFirst> ^ source1, System::Collections::Generic::IEnumerable<TSecond> ^ source2, System::Collections::Generic::IEnumerable<TThird> ^ source3);
public static System.Linq.IQueryable<(TFirst First, TSecond Second, TThird Third)> Zip<TFirst,TSecond,TThird> (this System.Linq.IQueryable<TFirst> source1, System.Collections.Generic.IEnumerable<TSecond> source2, System.Collections.Generic.IEnumerable<TThird> source3);
static member Zip : System.Linq.IQueryable<'First> * seq<'Second> * seq<'hird> -> System.Linq.IQueryable<ValueTuple<'First, 'Second, 'hird>>
<Extension()>
Public Function Zip(Of TFirst, TSecond, TThird) (source1 As IQueryable(Of TFirst), source2 As IEnumerable(Of TSecond), source3 As IEnumerable(Of TThird)) As IQueryable(Of ValueTuple(Of TFirst, TSecond, TThird))
Type Parameters
- TFirst
The type of the elements of the first input sequence.
- TSecond
The type of the elements of the second input sequence.
- TThird
The type of the elements of the third input sequence.
Parameters
- source1
- IQueryable<TFirst>
The first sequence to merge.
- source2
- IEnumerable<TSecond>
The second sequence to merge.
- source3
- IEnumerable<TThird>
The third sequence to merge.
Returns
A sequence of tuples with elements taken from the first, second and third sequences, in that order.
Applies to
Zip<TFirst,TSecond>(IQueryable<TFirst>, IEnumerable<TSecond>)
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
Produces a sequence of tuples with elements from the two specified sequences.
public:
generic <typename TFirst, typename TSecond>
[System::Runtime::CompilerServices::Extension]
static System::Linq::IQueryable<ValueTuple<TFirst, TSecond>> ^ Zip(System::Linq::IQueryable<TFirst> ^ source1, System::Collections::Generic::IEnumerable<TSecond> ^ source2);
public static System.Linq.IQueryable<(TFirst First, TSecond Second)> Zip<TFirst,TSecond> (this System.Linq.IQueryable<TFirst> source1, System.Collections.Generic.IEnumerable<TSecond> source2);
static member Zip : System.Linq.IQueryable<'First> * seq<'Second> -> System.Linq.IQueryable<ValueTuple<'First, 'Second>>
<Extension()>
Public Function Zip(Of TFirst, TSecond) (source1 As IQueryable(Of TFirst), source2 As IEnumerable(Of TSecond)) As IQueryable(Of ValueTuple(Of TFirst, TSecond))
Type Parameters
- TFirst
The type of the elements of the first input sequence.
- TSecond
The type of the elements of the second input sequence.
Parameters
- source1
- IQueryable<TFirst>
The first sequence to merge.
- source2
- IEnumerable<TSecond>
The second sequence to merge.
Returns
A sequence of tuples with elements taken from the first and second sequences, in that order.