This documentation is archived and is not being maintained.

IDictionary.Add Method

When implemented by a class, adds an element with the provided key and value to the IDictionary.

[Visual Basic]
Sub Add( _
   ByVal key As Object, _
   ByVal value As Object _
void Add(
   object key,
 object value
void Add(
   Object* key,
 Object* value
function Add(
   key : Object,
 value : Object


The Object to use as the key of the element to add.
The Object to use as the value of the element to add.


Exception Type Condition
ArgumentNullException key is a null reference (Nothing in Visual Basic).
ArgumentException An element with the same key already exists in the IDictionary.
NotSupportedException The IDictionary is read-only.


The IDictionary has a fixed size.


The Item property can also be used to add new elements by setting the value of a key that does not exist in the dictionary. For example: myCollection["myNonexistentKey"] = myValue. However, if the specified key already exists in the dictionary, setting the Item property overwrites the old value. In contrast, the Add method does not modify existing elements.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

IDictionary Interface | IDictionary Members | System.Collections Namespace | Item