IDictionary.Item Property
When implemented by a class, gets or sets the element with the specified key.
[C#] In C#, this property is the indexer for the IDictionary class.
[Visual Basic] Default Property Item( _ ByVal key As Object _ ) As Object [C#] object this[ object key ] {get; set;} [C++] __property Object* get_Item( Object* key ); __property void set_Item( Object* key, Object* ); [JScript] returnValue = IDictionaryObject.Item(key); IDictionaryObject.Item(key) = returnValue; -or- returnValue = IDictionaryObject(key); IDictionaryObject(key) = returnValue;
[JScript] In JScript, you can use the default indexed properties defined by a type, but you cannot explicitly define your own. However, specifying the expando attribute on a class automatically provides a default indexed property whose type is Object and whose index type is String.
Arguments [JScript]
- key
- The key of the element to get or set.
Parameters [Visual Basic, C#, C++]
- key
- The key of the element to get or set.
Property Value
The element with the specified key.
Exceptions
| Exception Type | Condition |
|---|---|
| ArgumentNullException | key is a null reference (Nothing in Visual Basic). |
| NotSupportedException | The property is set and the IDictionary is read-only.
-or- The property is set, key does not exist in the collection, and the IDictionary has a fixed size. |
Remarks
This property provides the ability to access a specific element in the collection by using the following syntax: myCollection[key].
When setting this property, if the specified key already exists in the dictionary, the value is replaced; otherwise, a new element is created. 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, Common Language Infrastructure (CLI) Standard
See Also
IDictionary Interface | IDictionary Members | System.Collections Namespace | Add