Hashtable.Item Property |
System.Collections.Hashtable
hashtablevariable .Item( key )
A reference to a Hashtable object
The key whose value is to be retrieved
An Object representing the value associated with key
Returns an Object that is the value associated with a particular key/value pair.
Item is the default property of the Hashtable object, and since it is parameterized, we can write:
hashtablevariable ( key )
Item is a read/write property. In other words, you can use the Item property to retrieve the value belonging to a particular key, as well as to modify the value belonging to a particular key.
If key does not exist in the hash table when you attempt to retrieve a value, the Item property returns Nothing .
If key does not exist in the hash table when you attempt to modify a value, the key and its associated value are added to the hash table, as a sort of implicit add. For example, if the key "AK" does not exist in a hash table, the code fragment:
hshStates.Item("AK") = "Alaska"
adds the key "AK" and its associated value, "Alaska" .
To guard against inadvertently adding a member to the hash table when you intend to modify an existing value, call the ContainsKey method beforehand.
You can also retrieve individual members of the Hashtable object by iterating it using the For Each...Next statement. Each iteration of the loop returns a DictionaryEntry object containing a single key/value pair. For information on the DictionaryEntry object, see the entry for the Hashtable.CopyTo method.