Partager via


OrderedDictionary.Clear Méthode

Définition

Supprime tous les éléments de la OrderedDictionary collection.

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

Implémente

Exceptions

La OrderedDictionary collection est en lecture seule.

Exemples

L’exemple de code suivant illustre la modification d’une OrderedDictionary collection. Dans cet exemple, la Clear méthode est utilisée pour vider le OrderedDictionary, puis la OrderedDictionary méthode est reremplie. Ce code fait partie d’un exemple de code plus large qui peut être consulté à l’adresse 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)

Remarques

Après avoir appelé la Clear méthode, la Count propriété est définie sur zéro et les références à d’autres objets provenant d’éléments de la collection sont également publiées. La capacité n’est pas modifiée suite à l’appel de cette méthode.

S’applique à