Поделиться через


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

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

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

Parameters

Return Value

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

Exceptions

Exception Condition
ArgumentNullException

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

Remarks

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

Silverlight

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

Platforms

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