OrderedDictionary.Clear Metoda
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Usuwa wszystkie elementy z kolekcji OrderedDictionary .
public:
virtual void Clear();
public void Clear ();
abstract member Clear : unit -> unit
override this.Clear : unit -> unit
Public Sub Clear ()
Kolekcja OrderedDictionary jest tylko do odczytu.
Poniższy przykład kodu pokazuje modyfikację OrderedDictionary kolekcji. W tym przykładzie Clear metoda jest używana do opróżniania OrderedDictionaryelementu , a następnie OrderedDictionary jest ponownie wypełniana. Ten kod jest częścią większego przykładu kodu, który można wyświetlić pod adresem 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 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)
Po wywołaniu Clear metody Count właściwość jest ustawiona na zero, a odwołania do innych obiektów z elementów kolekcji są również zwalniane. Pojemność nie jest zmieniana w wyniku wywołania tej metody.
Produkt | Wersje |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
UWP | 10.0 |
Opinia o produkcie .NET
.NET to projekt typu open source. Wybierz link, aby przekazać opinię: