KeyedCollection<TKey, TItem>.Contains Method (TKey)

Determines whether the collection contains an element with the specified key.

Namespace:  System.Collections.ObjectModel
Assembly:  mscorlib (in mscorlib.dll)


Public Function Contains ( _
    key As TKey _
) As Boolean
public bool Contains(
    TKey key


Return Value

Type: System.Boolean
true if the KeyedCollection<TKey, TItem> contains an element with the specified key; otherwise, false.


Exception Condition

key is nulla null reference (Nothing in Visual Basic).


If the KeyedCollection<TKey, TItem> has a lookup dictionary, key is used to search the dictionary. If there is no lookup dictionary, the key of each element is extracted using the GetKeyForItem method and compared with the specified key.

This method is an O(1) operation if the KeyedCollection<TKey, TItem> has a lookup dictionary; otherwise it is an O(n) operation, where n is Count.

Version Information


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0


For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.