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.

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 _
)
[C#]
void Add(
   object key,
 object value
);
[C++]
void Add(
   Object* key,
 Object* value
);
[JScript]
function Add(
   key : Object,
 value : Object
);

Parameters

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

Exceptions

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.

-or-

The IDictionary has a fixed size.

Remarks

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.

Requirements

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft