OrderedDictionary.Remove(Object) 메서드

정의

컬렉션에서 OrderedDictionary 지정된 키가 있는 항목을 제거합니다.

public:
 virtual void Remove(System::Object ^ key);
public void Remove(object key);
abstract member Remove : obj -> unit
override this.Remove : obj -> unit
Public Sub Remove (key As Object)

매개 변수

key
Object

제거할 항목의 키입니다.

구현

예외

컬렉션이 OrderedDictionary 읽기 전용입니다.

keynull입니다.

예제

다음 코드 예제에서는 컬렉션의 수정을 보여 줍니다 OrderedDictionary . 이 예제에서는 메서드를 Remove 사용하여 키를 "keyToDelete" 가진 항목을 제거합니다 OrderedDictionary. 이 코드는 에서 OrderedDictionary볼 수 있는 더 큰 코드 예제의 일부입니다.

// Modifying the OrderedDictionary
if (!myOrderedDictionary.IsReadOnly)
{
    // Insert a new key to the beginning of the OrderedDictionary
    myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1");

    // Modify the value of the entry with the key "testKey2"
    myOrderedDictionary["testKey2"] = "modifiedValue";

    // Remove the last entry from the OrderedDictionary: "testKey3"
    myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1);

    // Remove the "keyToDelete" entry, if it exists
    if (myOrderedDictionary.Contains("keyToDelete"))
    {
        myOrderedDictionary.Remove("keyToDelete");
    }
}
' Modifying the OrderedDictionary
If Not myOrderedDictionary.IsReadOnly Then

    ' Insert a new key to the beginning of the OrderedDictionary
    myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1")

    ' Modify the value of the entry with the key "testKey2"
    myOrderedDictionary("testKey2") = "modifiedValue"

    ' Remove the last entry from the OrderedDictionary: "testKey3"
    myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1)

    ' Remove the "keyToDelete" entry, if it exists
    If (myOrderedDictionary.Contains("keyToDelete")) Then
        myOrderedDictionary.Remove("keyToDelete")
    End If
End If

설명

제거된 항목 다음에 있는 항목은 비워진 지점을 차지하기 위해 위로 이동하고 이동하는 항목의 인덱스도 업데이트됩니다.

컬렉션에 OrderedDictionary 지정된 키가 OrderedDictionary 있는 항목이 없으면 변경되지 않은 상태로 유지되며 예외가 throw되지 않습니다.

적용 대상