Queryable.Except Queryable.Except Queryable.Except Queryable.Except Method

定義

產生兩個序列的差異。Produces the set difference of two sequences.

多載

Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)

使用指定的 IEqualityComparer<T> 來比較值,以便產生兩個序列的差異。Produces the set difference of two sequences by using the specified IEqualityComparer<T> to compare values.

Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>)

使用預設相等比較子來比較值,以便產生兩個序列的差異。Produces the set difference of two sequences by using the default equality comparer to compare values.

Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)

使用指定的 IEqualityComparer<T> 來比較值,以便產生兩個序列的差異。Produces the set difference of two sequences by using the specified IEqualityComparer<T> to compare values.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Linq::IQueryable<TSource> ^ Except(System::Linq::IQueryable<TSource> ^ source1, System::Collections::Generic::IEnumerable<TSource> ^ source2, System::Collections::Generic::IEqualityComparer<TSource> ^ comparer);
public static System.Linq.IQueryable<TSource> Except<TSource> (this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2, System.Collections.Generic.IEqualityComparer<TSource> comparer);
static member Except : System.Linq.IQueryable<'Source> * seq<'Source> * System.Collections.Generic.IEqualityComparer<'Source> -> System.Linq.IQueryable<'Source>
<Extension()>
Public Function Except(Of TSource) (source1 As IQueryable(Of TSource), source2 As IEnumerable(Of TSource), comparer As IEqualityComparer(Of TSource)) As IQueryable(Of TSource)

類型參數

TSource

輸入序列之項目的類型。The type of the elements of the input sequences.

參數

source1
IQueryable<TSource>

IQueryable<T>,其項目若未同時存在 source2 中,便會傳回這些項目。An IQueryable<T> whose elements that are not also in source2 will be returned.

source2
IEnumerable<TSource>

IEnumerable<T>,其項目若同時出現在第一個序列中,則不會出現在傳回的序列中。An IEnumerable<T> whose elements that also occur in the first sequence will not appear in the returned sequence.

comparer
IEqualityComparer<TSource>

用來比較值的 IEqualityComparer<T>An IEqualityComparer<T> to compare values.

傳回

IQueryable<TSource>

IQueryable<T>,其中包含兩個序列的差異。An IQueryable<T> that contains the set difference of the two sequences.

例外狀況

source1source2nullsource1 or source2 is null.

備註

方法會產生, 其代表以Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)結構化泛型方法的方式呼叫本身。 MethodCallExpression Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)The Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) method generates a MethodCallExpression that represents calling Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) itself as a constructed generic method. 然後, 它會MethodCallExpression將傳遞CreateQuery<TElement>(Expression)至由Provider source1參數IQueryProvider的屬性所表示之的方法。It then passes the MethodCallExpression to the CreateQuery<TElement>(Expression) method of the IQueryProvider represented by the Provider property of thesource1 parameter.

因執行代表呼叫Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)之運算式樹狀架構而產生的查詢行為, 取決於source1參數類型的實作為。The query behavior that occurs as a result of executing an expression tree that represents calling Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) depends on the implementation of the type of the source1 parameter. 預期的行為是除了也在中source1 source2的所有專案都會傳回, 而且comparer會用來比較值。The expected behavior is that all the elements in source1 are returned except for those that are also in source2, and comparer is used to compare values.

Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>)

使用預設相等比較子來比較值,以便產生兩個序列的差異。Produces the set difference of two sequences by using the default equality comparer to compare values.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Linq::IQueryable<TSource> ^ Except(System::Linq::IQueryable<TSource> ^ source1, System::Collections::Generic::IEnumerable<TSource> ^ source2);
public static System.Linq.IQueryable<TSource> Except<TSource> (this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2);
static member Except : System.Linq.IQueryable<'Source> * seq<'Source> -> System.Linq.IQueryable<'Source>
<Extension()>
Public Function Except(Of TSource) (source1 As IQueryable(Of TSource), source2 As IEnumerable(Of TSource)) As IQueryable(Of TSource)

類型參數

TSource

輸入序列之項目的類型。The type of the elements of the input sequences.

參數

source1
IQueryable<TSource>

IQueryable<T>,其項目若未同時存在 source2 中,便會傳回這些項目。An IQueryable<T> whose elements that are not also in source2 will be returned.

source2
IEnumerable<TSource>

IEnumerable<T>,其項目若同時出現在第一個序列中,則不會出現在傳回的序列中。An IEnumerable<T> whose elements that also occur in the first sequence will not appear in the returned sequence.

傳回

IQueryable<TSource>

IQueryable<T>,其中包含兩個序列的差異。An IQueryable<T> that contains the set difference of the two sequences.

例外狀況

source1source2nullsource1 or source2 is null.

範例

下列程式碼範例示範如何使用Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>)傳回僅出現在第一個來源序列中的元素。The following code example demonstrates how to use Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) to return those elements that only appear in the first source sequence.

double[] numbers1 = { 2.0, 2.1, 2.2, 2.3, 2.4, 2.5 };
double[] numbers2 = { 2.2 };

// Get the numbers from the first array that
// are NOT in the second array.
IEnumerable<double> onlyInFirstSet =
    numbers1.AsQueryable().Except(numbers2);

foreach (double number in onlyInFirstSet)
    Console.WriteLine(number);

/*
    This code produces the following output:

    2
    2.1
    2.3
    2.4
    2.5
*/

Dim numbers1() As Double = {2.0, 2.1, 2.2, 2.3, 2.4, 2.5}
Dim numbers2() As Double = {2.2}

' Get the numbers from the first array that
' are NOT in the second array.
Dim onlyInFirstSet As IEnumerable(Of Double) = _
    numbers1.AsQueryable().Except(numbers2)

Dim output As New System.Text.StringBuilder
For Each number As Double In onlyInFirstSet
    output.AppendLine(number)
Next

' Display the output.
MsgBox(output.ToString())

' This code produces the following output:
'
' 2
' 2.1
' 2.3
' 2.4
' 2.5

備註

方法會產生, 其代表以Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>)結構化泛型方法的方式呼叫本身。 MethodCallExpression Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>)The Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) method generates a MethodCallExpression that represents calling Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) itself as a constructed generic method. 然後, 它會MethodCallExpression將傳遞CreateQuery<TElement>(Expression)至由Provider source1參數IQueryProvider的屬性所表示之的方法。It then passes the MethodCallExpression to the CreateQuery<TElement>(Expression) method of the IQueryProvider represented by the Provider property of thesource1 parameter.

因執行代表呼叫Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>)之運算式樹狀架構而產生的查詢行為, 取決於source1參數類型的實作為。The query behavior that occurs as a result of executing an expression tree that represents calling Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) depends on the implementation of the type of the source1 parameter. 預期的行為是傳回中source1的所有專案, 但source2也是中的所有元素。The expected behavior is that all the elements in source1 are returned except for those that are also in source2.

適用於