OrderedDictionary.Clear Método

Definição

Remove todos os elementos da OrderedDictionary coleção.

public:
 virtual void Clear();
public void Clear();
abstract member Clear : unit -> unit
override this.Clear : unit -> unit
Public Sub Clear ()

Implementações

Exceções

A OrderedDictionary coleção é apenas de leitura.

Exemplos

O exemplo de código seguinte demonstra a modificação de uma OrderedDictionary coleção. Neste exemplo, o Clear método é usado para esvaziar o OrderedDictionary, e depois o OrderedDictionary é repovoado. Este código faz parte de um exemplo de código maior que pode ser visto em OrderedDictionary.

// Clear the OrderedDictionary and add new values
myOrderedDictionary.Clear();
myOrderedDictionary.Add("newKey1", "newValue1");
myOrderedDictionary.Add("newKey2", "newValue2");
myOrderedDictionary.Add("newKey3", "newValue3");

// Display the contents of the "new" Dictionary using an enumerator
IDictionaryEnumerator myEnumerator =
    myOrderedDictionary.GetEnumerator();

Console.WriteLine(
    "{0}Displaying the entries of a \"new\" OrderedDictionary.",
    Environment.NewLine);

DisplayEnumerator(myEnumerator);
' Clear the OrderedDictionary and add new values
myOrderedDictionary.Clear()
myOrderedDictionary.Add("newKey1", "newValue1")
myOrderedDictionary.Add("newKey2", "newValue2")
myOrderedDictionary.Add("newKey3", "newValue3")

' Display the contents of the "new" Dictionary Imports an enumerator
Dim myEnumerator As IDictionaryEnumerator = _
    myOrderedDictionary.GetEnumerator()

Console.WriteLine( _
    "{0}Displaying the entries of a 'new' OrderedDictionary.", _
    Environment.NewLine)

DisplayEnumerator(myEnumerator)

Observações

Após chamar o Clear método, a Count propriedade é definida como zero e as referências a outros objetos provenientes de elementos da coleção também são libertadas. A capacidade não é alterada como resultado da chamada deste método.

Aplica-se a