Export (0) Print
Expand All

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 bool Contains(
	TKey key


Type: TKey
The key to locate in the KeyedCollection<TKey, TItem>.

Return Value

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


key is null.

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.


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.

Community Additions

© 2015 Microsoft