共用方式為


Queryable.Zip 方法

定義

多載

名稱 Description
Zip<TFirst,TSecond,TResult>(IQueryable<TFirst>, IEnumerable<TSecond>, Expression<Func<TFirst,TSecond,TResult>>)

使用指定的述詞函式合併兩個序列。

Zip<TFirst,TSecond,TThird>(IQueryable<TFirst>, IEnumerable<TSecond>, IEnumerable<TThird>)

產生具有來自三個指定序列之元素的 Tuple 序列。

Zip<TFirst,TSecond>(IQueryable<TFirst>, IEnumerable<TSecond>)

產生具有來自兩個指定序列之元素的 Tuple 序列。

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

來源:
Queryable.cs
來源:
Queryable.cs
來源:
Queryable.cs
來源:
Queryable.cs
來源:
Queryable.cs

使用指定的述詞函式合併兩個序列。

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);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
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>
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
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)

類型參數

TFirst

第一個輸入序列元素的型別。

TSecond

第二個輸入序列元素的類型。

TResult

結果序列元素的類型。

參數

source1
IQueryable<TFirst>

第一個合併的序列。

source2
IEnumerable<TSecond>

第二個合併序列。

resultSelector
Expression<Func<TFirst,TSecond,TResult>>

一個指定如何合併兩個序列元素的函數。

傳回

IQueryable<TResult>

一個 IQueryable<T> 包含兩個輸入序列合併元素的 。

屬性

例外狀況

source1source2null

範例

以下程式碼範例示範如何使用此 Zip 方法合併兩個序列。

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

備註

Zip 方法產生的 是 MethodCallExpression ,代表 Zip 呼叫本身為一個構造化的泛型方法。 接著將 傳遞MethodCallExpressionCreateQuery<TElement>(Expression)IQueryProvider由參數Provider性質source1所表示的方法。

此方法將第一個序列中的每個元素與第二個序列中索引相同的元素合併。 若序列元素數不相同,方法會合併序列直到達到其中一個序列的末端。 例如,若一個序列有三個元素,另一個序列有四個元素,則最終序列將只有三個元素。

適用於

Zip<TFirst,TSecond,TThird>(IQueryable<TFirst>, IEnumerable<TSecond>, IEnumerable<TThird>)

來源:
Queryable.cs
來源:
Queryable.cs
來源:
Queryable.cs
來源:
Queryable.cs
來源:
Queryable.cs

產生具有來自三個指定序列之元素的 Tuple 序列。

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);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
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>>
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
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))

類型參數

TFirst

第一個輸入序列元素的型別。

TSecond

第二個輸入序列元素的類型。

TThird

第三個輸入序列元素的類型。

參數

source1
IQueryable<TFirst>

第一個合併的序列。

source2
IEnumerable<TSecond>

第二個合併序列。

source3
IEnumerable<TThird>

第三個合併序列。

傳回

IQueryable<ValueTuple<TFirst,TSecond,TThird>>

一串元組,元素依序取自第一、第二和第三序列。

屬性

適用於

Zip<TFirst,TSecond>(IQueryable<TFirst>, IEnumerable<TSecond>)

來源:
Queryable.cs
來源:
Queryable.cs
來源:
Queryable.cs
來源:
Queryable.cs
來源:
Queryable.cs

產生具有來自兩個指定序列之元素的 Tuple 序列。

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);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
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>>
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
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))

類型參數

TFirst

第一個輸入序列元素的型別。

TSecond

第二個輸入序列元素的類型。

參數

source1
IQueryable<TFirst>

第一個合併的序列。

source2
IEnumerable<TSecond>

第二個合併序列。

傳回

IQueryable<ValueTuple<TFirst,TSecond>>

一串元組,元素取自第一和第二序列,依序排列。

屬性

適用於