NamespaceSystem.Collections CreatableYes DescriptionThe Hashtable class implements a hash-based dictionary of value pairs. A hashtable represents a collection of values that are indexed by keys; these values and keys are associated in a dictionary of key/value pairs. A hashing function is used to speed up access to each pair. In .NET, both the values and the keys are objects of any type. The Hashtable class is somewhat more flexible than the standard VB Collection class. The following table lists some of the more useful and interesting members of the Hashtable class. Those marked with an asterisk (*) have separate entries in this chapter.
ExampleThis example makes use of a simple hashtable. ' ----- Build a simple hashtable. Dim nameHash As New Hashtable( ) nameHash.Add("Be", "Beethoven") nameHash.Add("Ch", "Chopin") nameHash.Add("Mo", "Mozart") ' ----- Select and remove items. MsgBox(nameHash.Item("Be")) ' Displays "Beethoven" nameHash.Remove("Ch") ' Removes "Chopin" MsgBox(nameHash.Count) ' Displays 2 nameHash.Clear( ) See AlsoCollection Class, Queue Class, Stack Class |