Export (0) Print
Expand All

Hashtable.Item Property

Gets or sets the value associated with the specified key.

[C#] In C#, this property is the indexer for the Hashtable class.

[Visual Basic]
Public Overridable Default Property Item( _
   ByVal key As Object _
) As Object  Implements IDictionary.Item
[C#]
public virtual object this[
 object key
] {get; set;}
[C++]
public: __property virtual Object* get_Item(
 Object* key
);
public: __property virtual void set_Item(
 Object* key,
   Object*
);
[JScript]
returnValue = HashtableObject.Item(key);
HashtableObject.Item(key) = returnValue;
-or-
returnValue = HashtableObject(key);
HashtableObject(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 whose value to get or set.

Parameters [Visual Basic, C#, C++]

key
The key whose value to get or set.

Property Value

The value associated with the specified key. If the specified key is not found, attempting to get it returns a null reference (Nothing in Visual Basic), and attempting to set it creates a new element using the specified key.

Implements

IDictionary.Item

Exceptions

Exception Type Condition
ArgumentNullException key is a null reference (Nothing in Visual Basic).
NotSupportedException The property is set and the Hashtable is read-only.

-or-

The property is set, key does not exist in the collection, and the Hashtable 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 Hashtable, the value is replaced; otherwise, a new element is created. In contrast, the Add method does not modify existing elements.

A key cannot be a null reference (Nothing in Visual Basic), but a value can be. To distinguish between a null reference (Nothing) that is returned because the specified key is not found and a null reference (Nothing) that is returned because the value of the specified key is a null reference (Nothing), use the Contains method or the ContainsKey method to determine if the key exists in the list.

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

Hashtable Class | Hashtable Members | System.Collections Namespace | Add

Show:
© 2014 Microsoft