Mono Class Library: System.Collections.Generic.IDictionary<TKey,TValue> Overview | Members

System.Collections.Generic.IDictionary<TKey,TValue>.Add Method

Adds an entry with the provided key and value to the current instance.

public void Add (TKey key, TValue value)

Parameters

key
The TKey to use as the key of the entry to add.
value
The TValue to use as the value of the entry to add.

Exceptions

TypeReason
ArgumentExceptionAn entry with the same key already exists in the current instance.
NotSupportedExceptionThe current instance is read-only.

Remarks

You can also use the IDictionary<TKey, TValue>.Item(TKey)(TKey) property to add new elements by setting the value of a key that does not exist in the dictionary. However, if the specified key already exists in the dictionary, setting the IDictionary<TKey, TValue>.Item(TKey)(TKey) property overwrites the old value. In contrast, the IDictionary<TKey, TValue>.Add(TKey, TValue)(TKey,TValue) method does not modify existing elements.

Implementations can vary in how they determine equality of objects.

Requirements

Namespace: System.Collections.Generic
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0