OrderedDictionary.Insert(Int32, Object, Object) 메서드

정의

지정한 인덱스에 있는 지정한 키와 값을 사용하여 OrderedDictionary 컬렉션에 새 엔트리를 삽입합니다.

public:
 virtual void Insert(int index, System::Object ^ key, System::Object ^ value);
public void Insert (int index, object key, object value);
public void Insert (int index, object key, object? value);
abstract member Insert : int * obj * obj -> unit
override this.Insert : int * obj * obj -> unit
Public Sub Insert (index As Integer, key As Object, value As Object)

매개 변수

index
Int32

요소를 삽입해야 하는 0부터 시작하는 인덱스입니다.

key
Object

추가할 엔트리의 키입니다.

value
Object

추가할 엔트리의 값입니다. 값은 null이 될 수 있습니다.

구현

예외

index이 범위에서 벗어난 경우.

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

예제

다음 코드 예제에서는 컬렉션의 수정을 보여 줍니다 OrderedDictionary . 이 예제에서는 메서드를 Insert 사용하여 의 시작 부분에 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 (!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

설명

매개 변수가 index 컬렉션의 항목 OrderedDictionary 수와 같으면 및 value 매개 변수가 컬렉션의 key 끝에 추가됩니다.

삽입 지점을 따르는 항목은 새 항목을 수용하기 위해 아래로 이동하고 이동된 항목의 인덱스도 업데이트됩니다.

적용 대상