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

Definizione

Determina se un IQueryable<T> contiene un elemento specificato.Determines whether an IQueryable<T> contains a specified element.

Overload

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

Determina se una sequenza contiene un elemento specificato utilizzando un oggetto specificato 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)

Determina se una sequenza contiene un elemento specificato usando l'operatore di uguaglianza predefinito.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>)

Determina se una sequenza contiene un elemento specificato utilizzando un oggetto specificato 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

Parametri di tipo

TSource

Tipo degli elementi di source.The type of the elements of source.

Parametri

source
IQueryable<TSource>

Un' IQueryable<T> in cui individuare item.An IQueryable<T> in which to locate item.

item
TSource TSource TSource TSource

Oggetto da individuare nella sequenza.The object to locate in the sequence.

comparer
IEqualityComparer<TSource>

Oggetto IEqualityComparer<T> per confrontare i valori.An IEqualityComparer<T> to compare values.

Restituisce

true Se la sequenza di input contiene un elemento con il valore specificato. in caso contrario, false.true if the input sequence contains an element that has the specified value; otherwise, false.

Eccezioni

Commenti

Il Contains<TSource>(IQueryable<TSource>, TSource, IEqualityComparer<TSource>) metodo genera un MethodCallExpression che rappresenta una chiamata Contains<TSource>(IQueryable<TSource>, TSource, IEqualityComparer<TSource>) stesso come un metodo generico costruito.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. Passa quindi il MethodCallExpression per il Execute<TResult>(Expression) metodo del IQueryProvider rappresentato dal Provider proprietà del source parametro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

Il comportamento delle query che si verifica in seguito all'esecuzione di un albero delle espressioni che rappresenta una chiamata Contains<TSource>(IQueryable<TSource>, TSource, IEqualityComparer<TSource>) dipende dall'implementazione del tipo del source parametro.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. Il comportamento previsto è che determina se source contiene item tramite comparer per confrontare i valori.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)

Determina se una sequenza contiene un elemento specificato usando l'operatore di uguaglianza predefinito.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

Parametri di tipo

TSource

Tipo degli elementi di source.The type of the elements of source.

Parametri

source
IQueryable<TSource>

Un' IQueryable<T> in cui individuare item.An IQueryable<T> in which to locate item.

item
TSource TSource TSource TSource

Oggetto da individuare nella sequenza.The object to locate in the sequence.

Restituisce

true Se la sequenza di input contiene un elemento con il valore specificato. in caso contrario, false.true if the input sequence contains an element that has the specified value; otherwise, false.

Eccezioni

Esempi

Esempio di codice seguente viene illustrato come utilizzare Contains<TSource>(IQueryable<TSource>, TSource) per determinare se una sequenza contiene un elemento specifico.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'. 

Commenti

Il Contains<TSource>(IQueryable<TSource>, TSource) metodo genera un MethodCallExpression che rappresenta una chiamata Contains<TSource>(IQueryable<TSource>, TSource) stesso come un metodo generico costruito.The Contains<TSource>(IQueryable<TSource>, TSource) method generates a MethodCallExpression that represents calling Contains<TSource>(IQueryable<TSource>, TSource) itself as a constructed generic method. Passa quindi il MethodCallExpression per il Execute<TResult>(Expression) metodo del IQueryProvider rappresentato dal Provider proprietà del source parametro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

Il comportamento delle query che si verifica in seguito all'esecuzione di un albero delle espressioni che rappresenta una chiamata Contains<TSource>(IQueryable<TSource>, TSource) dipende dall'implementazione del tipo del source parametro.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. Il comportamento previsto è che determina se source contiene item.The expected behavior is that it determines if source contains item.

Si applica a