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 abstract Add : 
        keyValuePair:KeyValuePair<'TKey, 'TValue> -> unit  
private override Add : 
        keyValuePair:KeyValuePair<'TKey, 'TValue> -> unit

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 a null reference (Nothing in Visual Basic).

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.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Show: