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);
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 パラメーターがコレクションの末尾に追加されます。
挿入ポイントの後に続くエントリは、新しいエントリに対応するように下に移動し、移動されたエントリのインデックスも更新されます。