OrderedDictionary.Clear メソッド

定義

OrderedDictionary コレクションからすべての要素を削除します。

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

実装

例外

OrderedDictionary コレクションは読み取り専用です。

次のコード例は、コレクションの変更を OrderedDictionary 示しています。 この例では、メソッドを Clear 使用して空に OrderedDictionaryし、再 OrderedDictionary 入力します。 このコードは、表示できるより大きなコード例の一部です 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)

注釈

メソッドを Clear 呼び出した後、プロパティは 0 に設定され、 Count コレクションの要素から他のオブジェクトへの参照も解放されます。 このメソッドを呼び出した結果、容量は変更されません。

適用対象