OrderedDictionary.Remove(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.
Remove a entrada com a chave especificada da OrderedDictionary coleção.
public:
virtual void Remove(System::Object ^ key);
public void Remove(object key);
abstract member Remove : obj -> unit
override this.Remove : obj -> unit
Public Sub Remove (key As Object)
Parâmetros
- key
- Object
A chave da entrada para remover.
Implementações
Exceções
A OrderedDictionary coleção é apenas de leitura.
key é null.
Exemplos
O exemplo de código seguinte demonstra a modificação de uma OrderedDictionary coleção. Neste exemplo, o Remove método é usado para remover a entrada com a chave "keyToDelete" do OrderedDictionary. 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
As entradas que seguem a entrada removida sobem para ocupar o lugar vago e os índices das entradas que avançam também são atualizados.
Se a OrderedDictionary coleção não contiver uma entrada com a chave especificada, esta OrderedDictionary permanece inalterada e não é lançada nenhuma exceção.