
322
|
Chapter 12: The Language Reference
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
Example
The sample code copies hashtable pairs to an array.
Dim nameTable As New Hashtable
Dim stateArray( ) As DictionaryEntry
' ----- Build the hashtable.
nameTable.Add("Ch", "Chopin")
nameTable.Add("Mo", "Mozart")
nameTable.Add("Be", "Beethoven")
ReDim stateArray(nameTable.Count - 1)
nameTable.CopyTo(stateArray, 0)
See Also
Hashtable Class, Hashtable.Keys Property
Hashtable.Item Property
Class
System.Collections.Hashtable
Syntax
Dim result As Object = hashtableVariable.Item(key)
key (required; any)
The key with the related value that is to be retrieved
Description
The Item property returns the hashtable value associated with a particular key.
Usage at a Glance
• Item is the default property of the Hashtable class, so “.Item” is optional. The
following two lines are equivalent.
resultObject = myHashtable.Item("abc")
resultObject = myHashtable("abc")
• The Item property can be used to add or update values. The statement:
myHashtable.Item("abc") = sourceObject
either updates the value associated with the key “abc” (if it already exists in the
hashtable) or adds it as a new item with the key “abc” (if it does not yet exist in
the hashtable).
•If
key does not exist in the hashtable when you attempt to retrieve a value, the
Item property returns
Nothing.
• To guard