Queryable.Intersect 메서드

정의

두 시퀀스의 교집합을 구합니다.Produces the set intersection of two sequences.

오버로드

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

기본 같음 비교자로 값을 비교하여 두 시퀀스의 교집합을 구합니다.Produces the set intersection of two sequences by using the default equality comparer to compare values.

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

지정된 IEqualityComparer<T>로 값을 비교하여 두 시퀀스의 교집합을 구합니다.Produces the set intersection of two sequences by using the specified IEqualityComparer<T> to compare values.

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

기본 같음 비교자로 값을 비교하여 두 시퀀스의 교집합을 구합니다.Produces the set intersection 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> ^ Intersect(System::Linq::IQueryable<TSource> ^ source1, System::Collections::Generic::IEnumerable<TSource> ^ source2);
public static System.Linq.IQueryable<TSource> Intersect<TSource> (this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2);
static member Intersect : System.Linq.IQueryable<'Source> * seq<'Source> -> System.Linq.IQueryable<'Source>
<Extension()>
Public Function Intersect(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>

source2에도 있는 고유 요소가 반환되는 시퀀스입니다.A sequence whose distinct elements that also appear in source2 are returned.

source2
IEnumerable<TSource>

첫 번째 시퀀스에도 있는 고유 요소가 반환되는 시퀀스입니다.A sequence whose distinct elements that also appear in the first sequence are returned.

반환

IQueryable<TSource>

두 시퀀스의 교집합이 들어 있는 시퀀스입니다.A sequence that contains the set intersection of the two sequences.

예외

source1 또는 source2null인 경우source1 or source2 is null.

예제

다음 코드 예제에서는를 사용 하 여 Intersect<TSource>(IQueryable<TSource>, IEnumerable<TSource>) 두 시퀀스 각각에 표시 되는 요소를 반환 하는 방법을 보여 줍니다.The following code example demonstrates how to use Intersect<TSource>(IQueryable<TSource>, IEnumerable<TSource>) to return the elements that appear in each of two sequences.

int[] id1 = { 44, 26, 92, 30, 71, 38 };
int[] id2 = { 39, 59, 83, 47, 26, 4, 30 };

// Get the numbers that occur in both arrays (id1 and id2).
IEnumerable<int> both = id1.AsQueryable().Intersect(id2);

foreach (int id in both)
    Console.WriteLine(id);

/*
    This code produces the following output:

    26
    30
*/

Dim id1() As Integer = {44, 26, 92, 30, 71, 38}
Dim id2() As Integer = {39, 59, 83, 47, 26, 4, 30}

' Get the numbers that occur in both arrays (id1 and id2).
Dim both As IEnumerable(Of Integer) = id1.AsQueryable().Intersect(id2)

Dim output As New System.Text.StringBuilder
For Each id As Integer In both
    output.AppendLine(id)
Next

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

' This code produces the following output:

' 26
' 30

설명

Intersect<TSource>(IQueryable<TSource>, IEnumerable<TSource>)메서드는 자신을 MethodCallExpression 생성 된 제네릭 메서드로 호출 하는을 생성 합니다 Intersect<TSource>(IQueryable<TSource>, IEnumerable<TSource>) .The Intersect<TSource>(IQueryable<TSource>, IEnumerable<TSource>) method generates a MethodCallExpression that represents calling Intersect<TSource>(IQueryable<TSource>, IEnumerable<TSource>) itself as a constructed generic method. 그런 다음 MethodCallExpression CreateQuery<TElement>(Expression) IQueryProvider Provider 매개 변수의 속성이 나타내는의 메서드에를 전달 합니다 source1 .It then passes the MethodCallExpression to the CreateQuery<TElement>(Expression) method of the IQueryProvider represented by the Provider property of the source1 parameter.

호출을 나타내는 식 트리를 실행 한 결과로 발생 하는 쿼리 동작은 Intersect<TSource>(IQueryable<TSource>, IEnumerable<TSource>) 매개 변수의 형식 구현에 따라 달라 집니다 source1 .The query behavior that occurs as a result of executing an expression tree that represents calling Intersect<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 that are also in source2 are returned.

적용 대상

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

지정된 IEqualityComparer<T>로 값을 비교하여 두 시퀀스의 교집합을 구합니다.Produces the set intersection 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> ^ Intersect(System::Linq::IQueryable<TSource> ^ source1, System::Collections::Generic::IEnumerable<TSource> ^ source2, System::Collections::Generic::IEqualityComparer<TSource> ^ comparer);
public static System.Linq.IQueryable<TSource> Intersect<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> Intersect<TSource> (this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2, System.Collections.Generic.IEqualityComparer<TSource>? comparer);
static member Intersect : System.Linq.IQueryable<'Source> * seq<'Source> * System.Collections.Generic.IEqualityComparer<'Source> -> System.Linq.IQueryable<'Source>
<Extension()>
Public Function Intersect(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>

source2에도 있는 고유 요소가 반환되는 IQueryable<T>입니다.An IQueryable<T> whose distinct elements that also appear in source2 are returned.

source2
IEnumerable<TSource>

첫 번째 시퀀스에도 있는 고유 요소가 반환되는 IEnumerable<T>입니다.An IEnumerable<T> whose distinct elements that also appear in the first sequence are returned.

comparer
IEqualityComparer<TSource>

값을 비교할 IEqualityComparer<T>입니다.An IEqualityComparer<T> to compare values.

반환

IQueryable<TSource>

두 시퀀스의 교집합이 들어 있는 IQueryable<T>입니다.An IQueryable<T> that contains the set intersection of the two sequences.

예외

source1 또는 source2null인 경우source1 or source2 is null.

설명

Intersect<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)메서드는 자신을 MethodCallExpression 생성 된 제네릭 메서드로 호출 하는을 생성 합니다 Intersect<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) .The Intersect<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) method generates a MethodCallExpression that represents calling Intersect<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) itself as a constructed generic method. 그런 다음 MethodCallExpression CreateQuery<TElement>(Expression) IQueryProvider Provider 매개 변수의 속성이 나타내는의 메서드에를 전달 합니다 source1 .It then passes the MethodCallExpression to the CreateQuery<TElement>(Expression) method of the IQueryProvider represented by the Provider property of the source1 parameter.

호출을 나타내는 식 트리를 실행 한 결과로 발생 하는 쿼리 동작은 Intersect<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) 매개 변수의 형식 구현에 따라 달라 집니다 source1 .The query behavior that occurs as a result of executing an expression tree that represents calling Intersect<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) depends on the implementation of the type of the source1 parameter. 예상 되는 동작은에도 있는 모든 요소가 반환 되는 것입니다 source1 source2 .The expected behavior is that all the elements in source1 that are also in source2 are returned. comparer매개 변수는 요소를 비교 하는 데 사용 됩니다.The comparer parameter is used to compare elements.

적용 대상