OrderedDictionary.Insert(Int32, Object, Object) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Insere uma nova entrada na OrderedDictionary coleção com a chave e valor especificados no índice especificado.
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)
Parâmetros
- index
- Int32
O índice baseado em zero no qual o elemento deve ser inserido.
- key
- Object
A chave da entrada para acrescentar.
- value
- Object
O valor da entrada a acrescentar. O valor pode ser null.
Implementações
Exceções
index está fora do alcance.
Esta coleção é só de leitura.
Exemplos
O exemplo de código seguinte demonstra a modificação de uma OrderedDictionary coleção. Neste exemplo, o Insert método é usado para adicionar uma nova entrada ao início do OrderedDictionary, movendo as restantes entradas para baixo. Este código faz parte de um exemplo de código maior que pode ser visto em 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
Observações
Se o index parâmetro for igual ao número de entradas na OrderedDictionary coleção, os key parâmetros e value são adicionados ao final da coleção.
As entradas que seguem o ponto de inserção descem para acomodar a nova entrada e os índices das entradas movidas também são atualizados.