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)

설명

메서드 Count 를 호출한 Clear 후 속성이 0으로 설정되고 컬렉션 요소의 다른 개체에 대한 참조도 해제됩니다. 이 메서드를 호출한 결과 용량이 변경되지 않습니다.

적용 대상