Collection<T>.Contains(T) Método
Definição
Determina se um elemento está no 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
O objeto a ser localizado no Collection<T>.The object to locate in the Collection<T>. O valor pode ser null
para tipos de referência.The value can be null
for reference types.
Retornos
true
se item
for encontrado no Collection<T>; caso contrário, false
.true
if item
is found in the Collection<T>; otherwise, false
.
Implementações
Comentários
Se o Collection<T> objeto for criado usando o construtor sem parâmetros, esse método determinará a igualdade usando o EqualityComparer<T>.Default comparador de igualdade padrão para T
, o tipo de valores na 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. Se T
o tipo não implementar a IEquatable<T> interface, o Equals método será usado.If type T
does not implement the IEquatable<T> interface, the Equals method is used.
Se o objeto de coleção for criado passando um IList<T> objeto para o construtor, o Contains método será determinado pela IEqualityComparer<T> interface usada por esse 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.
Esse método executa uma pesquisa linear; Portanto, o tempo médio de execução é proporcional ao Count .This method performs a linear search; therefore, the average execution time is proportional to Count. Ou seja, esse método é uma operação O ( n
), em que n
é Count .That is, this method is an O(n
) operation, where n
is Count.