IDictionary.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 o elemento com a chave especificada do IDictionary objeto.
public:
void Remove(System::Object ^ key);
public void Remove(object key);
abstract member Remove : obj -> unit
Public Sub Remove (key As Object)
Parâmetros
- key
- Object
A chave do elemento para remover.
Exceções
key é null.
Exemplos
O exemplo de código seguinte demonstra como implementar o Remove método. Este exemplo de código faz parte de um exemplo maior fornecido para a IDictionary classe.
public void Remove(object key)
{
if (key == null) throw new ArgumentNullException("key");
// Try to find the key in the DictionaryEntry array
Int32 index;
if (TryGetIndexOfKey(key, out index))
{
// If the key is found, slide all the items up.
Array.Copy(items, index + 1, items, index, ItemsInUse - index - 1);
ItemsInUse--;
}
else
{
// If the key is not in the dictionary, just return.
}
}
Public Sub Remove(ByVal key As Object) Implements IDictionary.Remove
If key = Nothing Then
Throw New ArgumentNullException("key")
End If
' Try to find the key in the DictionaryEntry array
Dim index As Integer
If TryGetIndexOfKey(key, index) Then
' If the key is found, slide all the items up.
Array.Copy(items, index + 1, items, index, (ItemsInUse - index) - 1)
ItemsInUse = ItemsInUse - 1
Else
' If the key is not in the dictionary, just return.
End If
End Sub
Observações
Se o IDictionary objeto não contiver um elemento com a chave especificada, o IDictionary objeto permanece inalterado. Nenhuma exceção é lançada.