OrderedDictionary.Contains(Object) Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Avgör om samlingen OrderedDictionary innehåller en specifik nyckel.
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
Parametrar
- key
- Object
Nyckeln som ska hittas OrderedDictionary i samlingen.
Returer
true om samlingen OrderedDictionary innehåller ett element med den angivna nyckeln, falseannars .
Implementeringar
Exempel
Följande kodexempel visar hur en OrderedDictionary samling har ändrats. I det här exemplet Contains används metoden för att avgöra om det finns en post innan du försöker ta bort den. Den här koden är en del av ett större kodexempel som kan visas på 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 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
Kommentarer
Item[] Om du använder egenskapen kan du returnera ett null-värde om nyckeln inte finns eller om nyckeln är null.
Contains Använd metoden för att avgöra om det finns en specifik nyckel i OrderedDictionary samlingen.
Den här metoden använder samlingens objekt Equals och metoder för item att avgöra om item det CompareTo finns.