The HashTable Collection

The System.Collections.HashTable collection can store items according to a key/value pair, where both key and value are of type Object. The HashTable peculiarity is that its items are organized based on the hash code of the key. The following code provides an example:

Dim ht As New Hashtableht.Add("Alessandro", "Del Sole")ht.Add("A string", 35)ht.Add(3.14, New Person)'Number of itemsConsole.WriteLine(ht.Count)'Removes an item based on the keyht.Remove("Alessandro")

Items within a HashTable can be accessed by the key, as shown in the last line of code in the preceding example. It also offers two methods named ContainsKey and ContainsValue that check whether a key or a value exists within the ...

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.