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:

image

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 enable checking if a key or a value exists within the collection, as demonstrated here:

Note that if you do not check if a key already exist, as in the preceding example, and ...

Get Visual Basic® 2010 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.