OrderedDictionary.Clear Metod

Definition

Tar bort alla element från OrderedDictionary samlingen.

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

Implementeringar

Undantag

Samlingen OrderedDictionary är skrivskyddad.

Exempel

Följande kodexempel visar hur en OrderedDictionary samling har ändrats. I det här exemplet Clear används metoden för att tömma OrderedDictionary, och fylls sedan i OrderedDictionary igen. Den här koden är en del av ett större kodexempel som kan visas på 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)

Kommentarer

När du har anropat Clear metoden Count anges egenskapen till noll och referenser till andra objekt från element i samlingen släpps också. Kapaciteten ändras inte till följd av att den här metoden anropas.

Gäller för