OrderedDictionary.Contains(Object) Metoda

Definicja

Określa, czy OrderedDictionary kolekcja zawiera określony klucz.

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

Klucz do zlokalizowania w kolekcji OrderedDictionary .

Zwraca

trueOrderedDictionary jeśli kolekcja zawiera element z określonym kluczem; w przeciwnym razie false.

Implementuje

Przykłady

Poniższy przykład kodu przedstawia modyfikację OrderedDictionary kolekcji. W tym przykładzie Contains metoda służy do określenia, czy przed podjęciem próby usunięcia wpisu istnieje. Ten kod jest częścią większego przykładu kodu, który można wyświetlić pod adresem 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

Uwagi

Item[] Użycie właściwości może zwrócić wartość null, jeśli klucz nie istnieje lub jeśli klucz ma nullwartość . Contains Użyj metody , aby określić, czy w kolekcji OrderedDictionary istnieje określony klucz.

Począwszy od .NET Framework 2.0, ta metoda używa metod item i CompareTo obiektów Equals kolekcji do określenia, czy item istnieje. We wcześniejszych wersjach .NET Framework ta determinacja została wykonana przy użyciu Equals metod item i CompareTo parametru w obiektach w kolekcji.

Dotyczy