OrderedDictionary.Insert(Int32, Object, Object) Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Vloží novou položku do OrderedDictionary kolekce se zadaným klíčem a hodnotou v zadaném indexu.
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)
Parametry
- index
- Int32
Index založený na nule, do kterého by měl být prvek vložen.
- key
- Object
Klíč položky, která se má přidat.
- value
- Object
Hodnota položky, kterou chcete přidat. Hodnota může být null.
Implementuje
Výjimky
index je mimo rozsah.
Tato kolekce je jen pro čtení.
Příklady
Následující příklad kódu ukazuje úpravy OrderedDictionary kolekce. V tomto příkladu Insert se metoda používá k přidání nové položky na začátek OrderedDictionary, přesunutí zbytku položek dolů. Tento kód je součástí většího příkladu kódu, který lze zobrazit na OrderedDictionaryadrese .
// 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
Poznámky
index Pokud je parametr roven počtu položek v OrderedDictionary kolekci, key připojí se parametry value na konec kolekce.
Položky, které následují za kurzorem, se přesunou dolů, aby se přizpůsobily nové položce, a indexy přesunutých položek se také aktualizují.