Queryable.Contains Queryable.Contains Queryable.Contains Queryable.Contains Method

定義

決定かどうか、IQueryable<T>指定された要素が含まれています。Determines whether an IQueryable<T> contains a specified element.

オーバーロード

Contains<TSource>(IQueryable<TSource>, TSource, IEqualityComparer<TSource>) Contains<TSource>(IQueryable<TSource>, TSource, IEqualityComparer<TSource>) Contains<TSource>(IQueryable<TSource>, TSource, IEqualityComparer<TSource>) 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) Contains<TSource>(IQueryable<TSource>, TSource) Contains<TSource>(IQueryable<TSource>, TSource) 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>) Contains<TSource>(IQueryable<TSource>, TSource, IEqualityComparer<TSource>) Contains<TSource>(IQueryable<TSource>, TSource, IEqualityComparer<TSource>) 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);
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>

IQueryable<T>を検索するitemします。An IQueryable<T> in which to locate item.

item
TSource TSource TSource TSource

シーケンス内で検索するオブジェクト。The object to locate in the sequence.

comparer
IEqualityComparer<TSource>

値を比較する IEqualityComparer<T>An IEqualityComparer<T> to compare values.

戻り値

true 入力シーケンスには、指定した値を持つ要素が含まれている場合それ以外の場合、falseします。true if the input sequence contains an element that has the specified value; otherwise, false.

例外

注釈

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. これは、後、渡します、MethodCallExpressionExecute<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) Contains<TSource>(IQueryable<TSource>, TSource) Contains<TSource>(IQueryable<TSource>, TSource) 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>

IQueryable<T>を検索するitemします。An IQueryable<T> in which to locate item.

item
TSource TSource TSource TSource

シーケンス内で検索するオブジェクト。The object to locate in the sequence.

戻り値

true 入力シーケンスには、指定した値を持つ要素が含まれている場合それ以外の場合、falseします。true if the input sequence contains an element that has the specified value; otherwise, false.

例外

次のコード例は、使用する方法を示します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. これは、後、渡します、MethodCallExpressionExecute<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.

適用対象