Export (0) Print
Expand All

Dictionary<TKey, TValue>::ICollection<KeyValuePair<TKey, TValue>>::Add Method

Adds the specified value to the ICollection<T> with the specified key.

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

private:
virtual void Add(
	KeyValuePair<TKey, TValue> keyValuePair
) sealed = ICollection<KeyValuePair<TKey, TValue>>::Add

Parameters

keyValuePair
Type: System.Collections.Generic::KeyValuePair<TKey, TValue>
The KeyValuePair<TKey, TValue> structure representing the key and value to add to the Dictionary<TKey, TValue>.

Implements

ICollection<T>::Add(T)

ExceptionCondition
ArgumentNullException

The key of keyValuePair is nullptr.

ArgumentException

An element with the same key already exists in the Dictionary<TKey, TValue>.

If Count is less than the capacity, this method approaches an O(1) operation. If the capacity needs to be increased to accommodate the new element, this method becomes an O(n) operation, where n is Count.

The following example shows how to use the ICollection<KeyValuePair<TKey, TValue>>::Add, ICollection<KeyValuePair<TKey, TValue>>::Contains, ICollection<KeyValuePair<TKey, TValue>>::CopyTo, and ICollection<KeyValuePair<TKey, TValue>>::Remove methods of the System.Collections.Generic::ICollection<T> generic interface to manipulate a Dictionary<TKey, TValue> object.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft