HashSet<T>.Add(T) Método
Definição
Adiciona o elemento especificado a um conjunto.Adds the specified element to a set.
public:
virtual bool Add(T item);
public:
bool Add(T item);
public bool Add (T item);
abstract member Add : 'T -> bool
override this.Add : 'T -> bool
member this.Add : 'T -> bool
Public Function Add (item As T) As Boolean
Parâmetros
- item
- T
O elemento a ser adicionado ao conjunto.The element to add to the set.
Retornos
true se o elemento for adicionado ao objeto HashSet<T>, false se o elemento já estiver presente.true if the element is added to the HashSet<T> object; false if the element is already present.
Implementações
Exemplos
O exemplo a seguir demonstra como criar e preencher dois HashSet<T> objetos.The following example demonstrates how to create and populate two HashSet<T> objects. Este exemplo faz parte de um exemplo maior fornecido para o UnionWith método.This example is part of a larger example provided for the UnionWith method.
HashSet<int> evenNumbers = new HashSet<int>();
HashSet<int> oddNumbers = new HashSet<int>();
for (int i = 0; i < 5; i++)
{
// Populate numbers with just even numbers.
evenNumbers.Add(i * 2);
// Populate oddNumbers with just odd numbers.
oddNumbers.Add((i * 2) + 1);
}
Comentários
Se Count já for igual à capacidade do HashSet<T> objeto, a capacidade será ajustada automaticamente para acomodar o novo item.If Count already equals the capacity of the HashSet<T> object, the capacity is automatically adjusted to accommodate the new item.
Se Count for menor que a capacidade da matriz interna, esse método será uma operação O (1).If Count is less than the capacity of the internal array, this method is an O(1) operation. Se o HashSet<T> objeto precisar ser redimensionado, esse método se tornará uma n operação O (), em que n é Count .If the HashSet<T> object must be resized, this method becomes an O(n) operation, where n is Count.