Contains Method (TKey)
Collapse the table of content
Expand the table of content

KeyedCollection(Of TKey, TItem).Contains Method (TKey)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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

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

'Declaration
Public Function Contains ( _
	key As TKey _
) As Boolean

Parameters

key
Type: TKey
The key to locate in the KeyedCollection(Of TKey, TItem).

Return Value

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

ExceptionCondition
ArgumentNullException

key is Nothing.

If the KeyedCollection(Of 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(Of TKey, TItem) has a lookup dictionary; otherwise it is an O(n) operation, where n is Count.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft