Export (0) Print
Expand All

IDictionary.Contains Method

Determines whether the IDictionary object contains an element with the specified key.

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

bool Contains (
	Object key
)
boolean Contains (
	Object key
)
function Contains (
	key : Object
) : boolean
Not applicable.

Parameters

key

The key to locate in the IDictionary object.

Return Value

true if the IDictionary contains an element with the key; otherwise, false.

Exception typeCondition

ArgumentNullException

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

Implementations can vary in whether they allow the key to be a null reference (Nothing in Visual Basic).

Starting with the .NET Framework 2.0, this method uses the collection’s objects’ Equals and CompareTo methods on item to determine whether item exists. In the earlier versions of the .NET Framework, this determination was made by using the Equals and CompareTo methods of the item parameter on the objects in the collection.

The following code example demonstrates how to implement the Contains method. This code example is part of a larger example provided for the IDictionary class.

public bool Contains(object key)
{
   Int32 index;
   return TryGetIndexOfKey(key, out index);
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft