Adds an element with the specified key and value to the dictionary.
- key
- The key of the element to add to the dictionary.
- value
- The value of the element to add to the dictionary.
Type Reason ArgumentException An element with the same key already exists in the dictionary. ArgumentNullException key is null.
You can also use the Dictionary<TKey, TValue>.Item(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 Dictionary<TKey, TValue>.Item(TKey) property overwrites the old value. In contrast, the Dictionary<TKey, TValue>.Add(TKey,TValue) method does not modify existing elements.
If Dictionary<TKey, TValue>.Count already equals the capacity, the capacity of the dictionary is increased.
A key cannot be ., but a value can be, if the value type TValue is a reference type.
Namespace: System.Collections.Generic
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0