IDictionary.Remove(Object) Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee verwijdert u het element met de opgegeven sleutel uit het IDictionary object.
public:
void Remove(System::Object ^ key);
public void Remove(object key);
abstract member Remove : obj -> unit
Public Sub Remove (key As Object)
Parameters
- key
- Object
De sleutel van het element dat moet worden verwijderd.
Uitzonderingen
key is null.
Het IDictionary object heeft het kenmerk Alleen-lezen.
– of –
De IDictionary heeft een vaste grootte.
Voorbeelden
In het volgende codevoorbeeld ziet u hoe u de Remove methode implementeert. Dit codevoorbeeld maakt deel uit van een groter voorbeeld voor de IDictionary klasse.
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
Opmerkingen
Als het IDictionary object geen element met de opgegeven sleutel bevat, blijft het IDictionary ongewijzigd. Er wordt geen uitzondering opgeworpen.