SortedList<TKey,TValue>.Remove(TKey) Metodo

Definizione

Rimuove l'elemento con la chiave specificata da SortedList<TKey,TValue>.

public:
 virtual bool Remove(TKey key);
public bool Remove(TKey key);
abstract member Remove : 'Key -> bool
override this.Remove : 'Key -> bool
Public Function Remove (key As TKey) As Boolean

Parametri

key
TKey

Chiave dell'elemento da rimuovere.

Valori restituiti

true se l'elemento viene rimosso correttamente; in caso contrario, false. Questo metodo restituisce false anche se key non è stato trovato nell'oggetto originale SortedList<TKey,TValue>.

Implementazioni

Eccezioni

key è null.

Esempio

Nell'esempio di codice seguente viene illustrato come rimuovere una coppia chiave/valore dall'elenco ordinato usando il Remove metodo .

Questo esempio di codice fa parte di un esempio più ampio fornito per la SortedList<TKey,TValue> classe .

// Use the Remove method to remove a key/value pair.
Console.WriteLine("\nRemove(\"doc\")");
openWith.Remove("doc");

if (!openWith.ContainsKey("doc"))
{
    Console.WriteLine("Key \"doc\" is not found.");
}
' Use the Remove method to remove a key/value pair.
Console.WriteLine(vbLf + "Remove(""doc"")")
openWith.Remove("doc")

If Not openWith.ContainsKey("doc") Then
    Console.WriteLine("Key ""doc"" is not found.")
End If
// Use the Remove method to remove a key/value pair.
printfn "\nRemove(\"doc\")"
openWith.Remove("doc") |> ignore

if not (openWith.ContainsKey("doc")) then
    printfn "Key \"doc\" is not found."

Commenti

Questo metodo esegue una ricerca binaria; Tuttavia, gli elementi vengono spostati fino a riempire il punto aperto, quindi questo metodo è un'operazione O(n), dove n è Count.

Si applica a

Vedi anche