Compartilhar via


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 é somente leitura.

Exemplos

O exemplo de código a seguir demonstra a modificação de uma OrderedDictionary coleção. Neste exemplo, o Clear método é usado para esvaziar o OrderedDictionarye, em seguida, o OrderedDictionary é repovoado. Esse código faz parte de um exemplo de código maior que pode ser exibido 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)

Comentários

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

Aplica-se a