Aracılığıyla paylaş


OrderedDictionary.Clear Yöntem

Tanım

Koleksiyondaki OrderedDictionary tüm öğeleri kaldırır.

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

Uygulamalar

Özel durumlar

Koleksiyon OrderedDictionary salt okunurdur.

Örnekler

Aşağıdaki kod örneği bir OrderedDictionary koleksiyonun değiştirilmesini gösterir. Bu örnekte yöntemi, Clear öğesini boşaltmak OrderedDictionaryiçin kullanılır ve ardından OrderedDictionary yeniden doldurulur. Bu kod, adresinde OrderedDictionarygörüntülenebilen daha büyük bir kod örneğinin parçasıdır.

// 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)

Açıklamalar

yöntemi Count çağrıldıktan Clear sonra özelliği sıfır olarak ayarlanır ve koleksiyonun öğelerindeki diğer nesnelere başvurular da serbest bırakılır. Bu yöntemin çağrılması sonucunda kapasite değiştirilmez.

Şunlara uygulanır