Queryable.Contains 메서드

정의

IQueryable<T>에 지정된 요소가 들어 있는지 확인합니다.Determines whether an IQueryable<T> contains a specified element.

오버로드

Contains<TSource>(IQueryable<TSource>, TSource, IEqualityComparer<TSource>)

지정된 IEqualityComparer<T>를 사용하여 시퀀스에 지정된 요소가 들어 있는지 확인합니다.Determines whether a sequence contains a specified element by using a specified IEqualityComparer<T>.

Contains<TSource>(IQueryable<TSource>, TSource)

기본 같음 비교자를 사용하여 시퀀스에 지정된 요소가 들어 있는지 확인합니다.Determines whether a sequence contains a specified element by using the default equality comparer.

Contains<TSource>(IQueryable<TSource>, TSource, IEqualityComparer<TSource>)

지정된 IEqualityComparer<T>를 사용하여 시퀀스에 지정된 요소가 들어 있는지 확인합니다.Determines whether a sequence contains a specified element by using a specified IEqualityComparer<T>.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static bool Contains(System::Linq::IQueryable<TSource> ^ source, TSource item, System::Collections::Generic::IEqualityComparer<TSource> ^ comparer);
public static bool Contains<TSource> (this System.Linq.IQueryable<TSource> source, TSource item, System.Collections.Generic.IEqualityComparer<TSource> comparer);
public static bool Contains<TSource> (this System.Linq.IQueryable<TSource> source, TSource item, System.Collections.Generic.IEqualityComparer<TSource>? comparer);
static member Contains : System.Linq.IQueryable<'Source> * 'Source * System.Collections.Generic.IEqualityComparer<'Source> -> bool
<Extension()>
Public Function Contains(Of TSource) (source As IQueryable(Of TSource), item As TSource, comparer As IEqualityComparer(Of TSource)) As Boolean

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

매개 변수

source
IQueryable<TSource>

item을 찾을 IQueryable<T>입니다.An IQueryable<T> in which to locate item.

item
TSource

시퀀스에서 찾을 개체입니다.The object to locate in the sequence.

comparer
IEqualityComparer<TSource>

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

반환

Boolean

입력 시퀀스에 지정된 값을 갖는 요소가 들어 있으면 true이고, 그렇지 않으면 false입니다.true if the input sequence contains an element that has the specified value; otherwise, false.

예외

source이(가) null인 경우source is null.

설명

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

호출을 나타내는 식 트리를 실행 한 결과로 발생 하는 쿼리 동작은 Contains<TSource>(IQueryable<TSource>, TSource, IEqualityComparer<TSource>) 매개 변수의 형식 구현에 따라 달라 집니다 source .The query behavior that occurs as a result of executing an expression tree that represents calling Contains<TSource>(IQueryable<TSource>, TSource, IEqualityComparer<TSource>) depends on the implementation of the type of the source parameter. 예상 되는 동작은 source item 를 사용 하 여 comparer 값을 비교 하는지 여부를 확인 하는 것입니다.The expected behavior is that it determines if source contains item by using comparer to compare values.

적용 대상

Contains<TSource>(IQueryable<TSource>, TSource)

기본 같음 비교자를 사용하여 시퀀스에 지정된 요소가 들어 있는지 확인합니다.Determines whether a sequence contains a specified element by using the default equality comparer.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static bool Contains(System::Linq::IQueryable<TSource> ^ source, TSource item);
public static bool Contains<TSource> (this System.Linq.IQueryable<TSource> source, TSource item);
static member Contains : System.Linq.IQueryable<'Source> * 'Source -> bool
<Extension()>
Public Function Contains(Of TSource) (source As IQueryable(Of TSource), item As TSource) As Boolean

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

매개 변수

source
IQueryable<TSource>

item을 찾을 IQueryable<T>입니다.An IQueryable<T> in which to locate item.

item
TSource

시퀀스에서 찾을 개체입니다.The object to locate in the sequence.

반환

Boolean

입력 시퀀스에 지정된 값을 갖는 요소가 들어 있으면 true이고, 그렇지 않으면 false입니다.true if the input sequence contains an element that has the specified value; otherwise, false.

예외

source이(가) null인 경우source is null.

예제

다음 코드 예제에서는를 사용 하 여 Contains<TSource>(IQueryable<TSource>, TSource) 시퀀스에 특정 요소가 들어 있는지 여부를 확인 하는 방법을 보여 줍니다.The following code example demonstrates how to use Contains<TSource>(IQueryable<TSource>, TSource) to determine whether a sequence contains a specific element.

string[] fruits = { "apple", "banana", "mango",
                    "orange", "passionfruit", "grape" };

// The string to search for in the array.
string mango = "mango";

bool hasMango = fruits.AsQueryable().Contains(mango);

Console.WriteLine(
    "The array {0} contain '{1}'.",
    hasMango ? "does" : "does not",
    mango);

// This code produces the following output:
//
// The array does contain 'mango'.
Dim fruits() As String = {"apple", "banana", "mango", _
                        "orange", "passionfruit", "grape"}

' The string to search for in the array.
Dim mango As String = "mango"

Dim hasMango As Boolean = fruits.AsQueryable().Contains(mango)

MsgBox(String.Format("The array {0} contain '{1}'.", _
        IIf(hasMango, "does", "does not"), mango))

' This code produces the following output:
'
' The array does contain 'mango'.

설명

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

호출을 나타내는 식 트리를 실행 한 결과로 발생 하는 쿼리 동작은 Contains<TSource>(IQueryable<TSource>, TSource) 매개 변수의 형식 구현에 따라 달라 집니다 source .The query behavior that occurs as a result of executing an expression tree that represents calling Contains<TSource>(IQueryable<TSource>, TSource) depends on the implementation of the type of the source parameter. 예상 되는 동작은에가 포함 되어 있는지 여부를 확인 하는 것입니다 source item .The expected behavior is that it determines if source contains item.

적용 대상