IDictionary.Contains(Object) Metoda
Definicja
Określa, czy IDictionary obiekt zawiera element z określonym kluczem.Determines whether the IDictionary object contains an element with the specified key.
public:
bool Contains(System::Object ^ key);
public bool Contains (object key);
abstract member Contains : obj -> bool
Public Function Contains (key As Object) As Boolean
Parametry
- key
- Object
Klucz, który ma zostać zlokalizowany w IDictionary obiekcie.The key to locate in the IDictionary object.
Zwraca
true
Jeśli IDictionary zawiera element z kluczem; w przeciwnym razie, false
.true
if the IDictionary contains an element with the key; otherwise, false
.
Wyjątki
key
to null
.key
is null
.
Przykłady
Poniższy przykład kodu demonstruje, jak zaimplementować Contains metodę.The following code example demonstrates how to implement the Contains method. Ten przykład kodu jest częścią większego przykładu dostarczonego dla IDictionary klasy.This code example is part of a larger example provided for the IDictionary class.
public:
virtual bool Contains(Object^ key)
{
int index;
return TryGetIndexOfKey(key, &index);
}
public bool Contains(object key)
{
Int32 index;
return TryGetIndexOfKey(key, out index);
}
Public Function Contains(ByVal key As Object) As Boolean Implements IDictionary.Contains
Dim index As Integer
Return TryGetIndexOfKey(key, index)
End Function
Uwagi
Implementacje mogą się różnić w zależności od tego, czy zezwalają na klucz null
.Implementations can vary in whether they allow the key to be null
.
Począwszy od .NET Framework 2,0, ta metoda używa obiektów Equals i metod kolekcji, CompareTo item
Aby określić, czy item
istnieje.Starting with the .NET Framework 2.0, this method uses the collection's objects' Equals and CompareTo methods on item
to determine whether item
exists. We wcześniejszych wersjach .NET Framework to ustalenie zostało wykonane przy użyciu Equals CompareTo metod i item
parametru dla obiektów w kolekcji.In the earlier versions of the .NET Framework, this determination was made by using the Equals and CompareTo methods of the item
parameter on the objects in the collection.