Adds an entry with the provided key and value to the current instance.
- 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.
Type Reason ArgumentException An entry with the same key already exists in the current instance. NotSupportedException The current instance is read-only.
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.
Namespace: System.Collections.Generic
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0