Queryable.Contains Método

Definición

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

Sobrecargas

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

Determina si una secuencia contiene un elemento especificado utilizando un objeto IEqualityComparer<T> determinado.Determines whether a sequence contains a specified element by using a specified IEqualityComparer<T>.

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

Determina si una secuencia contiene un elemento especificado utilizando el comparador de igualdad predeterminado.Determines whether a sequence contains a specified element by using the default equality comparer.

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

Determina si una secuencia contiene un elemento especificado utilizando un objeto IEqualityComparer<T> determinado.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

Parámetros de tipo

TSource

Tipo de los elementos de source.The type of the elements of source.

Parámetros

source
IQueryable<TSource>

IQueryable<T> en el que se va a buscar item.An IQueryable<T> in which to locate item.

item
TSource

Objeto que se va a buscar en la secuencia.The object to locate in the sequence.

comparer
IEqualityComparer<TSource>

IEqualityComparer<T> para comparar valores.An IEqualityComparer<T> to compare values.

Devoluciones

Boolean

true si la secuencia de entrada contiene un elemento que tiene el valor especificado; de lo contrario, false.true if the input sequence contains an element that has the specified value; otherwise, false.

Excepciones

source es null.source is null.

Comentarios

El Contains<TSource>(IQueryable<TSource>, TSource, IEqualityComparer<TSource>) método genera un MethodCallExpression que representa la llamada a Contains<TSource>(IQueryable<TSource>, TSource, IEqualityComparer<TSource>) sí mismo como un método genérico construido.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. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Contains<TSource>(IQueryable<TSource>, TSource, IEqualityComparer<TSource>) la llamada depende de la implementación del tipo del source parámetro.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. El comportamiento esperado es que determina si source contiene mediante item comparer para comparar valores.The expected behavior is that it determines if source contains item by using comparer to compare values.

Se aplica a

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

Determina si una secuencia contiene un elemento especificado utilizando el comparador de igualdad predeterminado.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

Parámetros de tipo

TSource

Tipo de los elementos de source.The type of the elements of source.

Parámetros

source
IQueryable<TSource>

IQueryable<T> en el que se va a buscar item.An IQueryable<T> in which to locate item.

item
TSource

Objeto que se va a buscar en la secuencia.The object to locate in the sequence.

Devoluciones

Boolean

true si la secuencia de entrada contiene un elemento que tiene el valor especificado; de lo contrario, false.true if the input sequence contains an element that has the specified value; otherwise, false.

Excepciones

source es null.source is null.

Ejemplos

En el ejemplo de código siguiente se muestra cómo utilizar Contains<TSource>(IQueryable<TSource>, TSource) para determinar si una secuencia contiene un elemento específico.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'.

Comentarios

El Contains<TSource>(IQueryable<TSource>, TSource) método genera un MethodCallExpression que representa la llamada a Contains<TSource>(IQueryable<TSource>, TSource) sí mismo como un método genérico construido.The Contains<TSource>(IQueryable<TSource>, TSource) method generates a MethodCallExpression that represents calling Contains<TSource>(IQueryable<TSource>, TSource) itself as a constructed generic method. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Contains<TSource>(IQueryable<TSource>, TSource) la llamada depende de la implementación del tipo del source parámetro.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. El comportamiento esperado es que determina si source contiene item .The expected behavior is that it determines if source contains item.

Se aplica a