Бөлісу құралы:


Queryable.Except Метод

Определение

Создает разницу набора двух последовательностей.

Перегрузки

Имя Описание
Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>)

Создает различие набора двух последовательностей с помощью сравнения значений по умолчанию.

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

Создает различие набора двух последовательностей с помощью указанного IEqualityComparer<T> для сравнения значений.

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

Исходный код:
Queryable.cs
Исходный код:
Queryable.cs
Исходный код:
Queryable.cs
Исходный код:
Queryable.cs
Исходный код:
Queryable.cs

Создает различие набора двух последовательностей с помощью сравнения значений по умолчанию.

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);
[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<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>
[<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 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

Тип элементов входных последовательностей.

Параметры

source1
IQueryable<TSource>

Возвращается IQueryable<T> элементы, которые не находятся в source2 ней.

source2
IEnumerable<TSource>

Элементы IEnumerable<T> , которые также происходят в первой последовательности, не будут отображаться в возвращаемой последовательности.

Возвращаемое значение

IQueryable<TSource>

Значение IQueryable<T> , содержащее разницу набора двух последовательностей.

Атрибуты

Исключения

source1 или source2 есть null.

Примеры

В следующем примере кода показано, как использовать Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) для возврата этих элементов, которые отображаются только в первой исходной последовательности.

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>) себя как созданный универсальный метод. Затем он передает MethodCallExpressionCreateQuery<TElement>(Expression) метод IQueryProvider метода, представленного Provider свойствомsource1 параметра.

Поведение запроса, возникающее в результате выполнения дерева выражений, представляющего вызов Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) , зависит от реализации типа source1 параметра. Ожидаемое поведение заключается в том, что возвращаются все элементы source1 , кроме тех, в которых также source2находятся.

Применяется к

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

Исходный код:
Queryable.cs
Исходный код:
Queryable.cs
Исходный код:
Queryable.cs
Исходный код:
Queryable.cs
Исходный код:
Queryable.cs

Создает различие набора двух последовательностей с помощью указанного IEqualityComparer<T> для сравнения значений.

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);
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);
[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<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>
[<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 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

Тип элементов входных последовательностей.

Параметры

source1
IQueryable<TSource>

Возвращается IQueryable<T> элементы, которые не находятся в source2 ней.

source2
IEnumerable<TSource>

Элементы IEnumerable<T> , которые также происходят в первой последовательности, не будут отображаться в возвращаемой последовательности.

comparer
IEqualityComparer<TSource>

Значение для сравнения значений IEqualityComparer<T> .

Возвращаемое значение

IQueryable<TSource>

Значение IQueryable<T> , содержащее разницу набора двух последовательностей.

Атрибуты

Исключения

source1 или source2 есть null.

Комментарии

Метод Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) создает объект MethodCallExpression , представляющий Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) себя как созданный универсальный метод. Затем он передает MethodCallExpressionCreateQuery<TElement>(Expression) метод IQueryProvider метода, представленного Provider свойствомsource1 параметра.

Поведение запроса, возникающее в результате выполнения дерева выражений, представляющего вызов Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) , зависит от реализации типа source1 параметра. Ожидаемое поведение заключается в том, что возвращаются все элементы source1 , кроме тех, в которых также source2находятся, и comparer используется для сравнения значений.

Применяется к