共用方式為


PropertyCollection.IDictionary.Contains(Object) 方法

定義

判斷 IDictionary 物件是否包含具有指定索引鍵的項目。

 virtual bool System.Collections.IDictionary.Contains(System::Object ^ value) = System::Collections::IDictionary::Contains;
bool IDictionary.Contains (object value);
abstract member System.Collections.IDictionary.Contains : obj -> bool
override this.System.Collections.IDictionary.Contains : obj -> bool
Function Contains (value As Object) As Boolean Implements IDictionary.Contains

參數

value
Object

要在 IDictionary 物件中尋找的索引鍵。

傳回

如果 true 包含具有該索引鍵的項目,則為 IDictionary,否則為 false

實作

例外狀況

keynull

範例

下列範例示範如何實作 Contains 方法。 這個範例是提供給 類別之較大範例的 IDictionary 一部分。

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

適用於