Collection<T>.Contains(T) Método
Definición
Determina si un elemento se encuentra en Collection<T>.Determines whether an element is in the Collection<T>.
public:
virtual bool Contains(T item);
public bool Contains (T item);
abstract member Contains : 'T -> bool
override this.Contains : 'T -> bool
Public Function Contains (item As T) As Boolean
Parámetros
- item
- T
Objeto que se va a buscar en Collection<T>.The object to locate in the Collection<T>. El valor puede ser null
para los tipos de referencia.The value can be null
for reference types.
Devoluciones
true
si item
se encuentra en la matriz Collection<T>; en caso contrario, false
.true
if item
is found in the Collection<T>; otherwise, false
.
Implementaciones
Comentarios
Si el Collection<T> objeto se crea utilizando el constructor sin parámetros, este método determina la igualdad usando el comparador de igualdad predeterminado EqualityComparer<T>.Default para T
, el tipo de valores de la lista.If the Collection<T> object is created using the parameterless constructor, this method determines equality using the default equality comparer EqualityComparer<T>.Default for T
, the type of values in the list. Si el tipo no T
implementa la IEquatable<T> interfaz, Equals se utiliza el método.If type T
does not implement the IEquatable<T> interface, the Equals method is used.
Si el objeto de colección se crea pasando un IList<T> objeto al constructor, el Contains método lo determinará la IEqualityComparer<T> interfaz utilizada por ese IList<T> objeto.If the Collection object is created by passing an IList<T> object to the constructor, the Contains method will be determined by the IEqualityComparer<T> interface used by that IList<T> object.
Este método realiza una búsqueda lineal; por lo tanto, el tiempo medio de ejecución es proporcional a Count .This method performs a linear search; therefore, the average execution time is proportional to Count. Es decir, este método es una operación O ( n
), donde n
es Count .That is, this method is an O(n
) operation, where n
is Count.