IDictionary.Remove(Object) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Rimuove l'elemento con la chiave specificata dall'oggetto IDictionary .
public:
void Remove(System::Object ^ key);
public void Remove(object key);
abstract member Remove : obj -> unit
Public Sub Remove (key As Object)
Parametri
- key
- Object
Chiave dell'elemento da rimuovere.
Eccezioni
key è null.
Esempio
Nell'esempio di codice seguente viene illustrato come implementare il Remove metodo . Questo esempio di codice fa parte di un esempio più ampio fornito per la 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
Commenti
Se l'oggetto IDictionary non contiene un elemento con la chiave specificata, rimane IDictionary invariato. Non viene generata alcuna eccezione.