Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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

 

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>.

Exception Condition
ArgumentNullException

The key of keyValuePair is null.

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 ICollection<T> generic interface to manipulate a Dictionary<TKey, TValue> object.

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

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2017 Microsoft