OrderedDictionary.Clear Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Odebere všechny prvky z OrderedDictionary kolekce.
public:
virtual void Clear();
public void Clear();
abstract member Clear : unit -> unit
override this.Clear : unit -> unit
Public Sub Clear ()
Implementuje
Výjimky
Kolekce OrderedDictionary je jen pro čtení.
Příklady
Následující příklad kódu ukazuje úpravy OrderedDictionary kolekce. V tomto příkladu se Clear metoda použije k vyprázdnění OrderedDictionarya pak se OrderedDictionary znovu vyprázdní. Tento kód je součástí většího příkladu kódu, který lze zobrazit na OrderedDictionaryadrese .
// 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)
Poznámky
Po volání Clear metody je vlastnost nastavena na nulu Count a odkazy na jiné objekty z elementů kolekce jsou také vydány. Kapacita se nezmění v důsledku volání této metody.