OrderedDictionary.Insert(Int32, Object, Object) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 인덱스에 지정된 키와 값을 사용하여 컬렉션에 새 항목을 OrderedDictionary 삽입합니다.
public:
virtual void Insert(int index, System::Object ^ key, System::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 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 수와 같으면 컬렉션 key 의 끝에 매개 변수와 value 매개 변수가 추가됩니다.
삽입 지점 다음에 있는 항목은 새 항목을 수용하기 위해 아래로 이동하고 이동된 항목의 인덱스도 업데이트됩니다.