OrderedDictionary.Contains(Object) Metoda

Definice

Určuje, zda OrderedDictionary kolekce obsahuje konkrétní klíč.

public:
 virtual bool Contains(System::Object ^ key);
public bool Contains (object key);
abstract member Contains : obj -> bool
override this.Contains : obj -> bool
Public Function Contains (key As Object) As Boolean

Parametry

key
Object

Klíč, který se má v kolekci OrderedDictionary najít.

Návraty

trueOrderedDictionary pokud kolekce obsahuje prvek se zadaným klíčem, falsev opačném případě .

Implementuje

Příklady

Následující příklad kódu ukazuje úpravu OrderedDictionary kolekce. V tomto příkladu Contains se metoda používá k určení, jestli existuje položka před pokusem o jeho odebrání. Tento kód je součástí většího příkladu kódu, který lze zobrazit na adrese 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 (!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

Poznámky

Item[] Použití vlastnosti může vrátit hodnotu null, pokud klíč neexistuje nebo pokud je nullklíč . Contains Pomocí metody zjistěte, jestli v kolekci OrderedDictionary existuje konkrétní klíč.

Počínaje rozhraním .NET Framework 2.0 tato metoda používá objekty Equals kolekce a CompareTo metody na item k určení, zda item existuje. V dřívějších verzích rozhraní .NET Framework bylo toto určení provedeno pomocí Equals metod a CompareTo parametru item u objektů v kolekci.

Platí pro