Use a Hashtable Instead of a Generic Collection

Problem

You need a dictionary (key-based) collection, or you want to replace the Visual Basic generic collection with a more powerful alternative.

Solution

Use the System.Collections.Hashtable type.

Discussion

The Hashtable class is a dictionary collection, where every item is indexed with a unique value. Hashtable collections are ideal for situations where you need to quickly retrieve individual items, because you can look up items using the corresponding key values, rather than by iterating through the contents of the entire collection. However, unlike arrays or the ArrayList class, you can’t access items using an index number.

When using a Hashtable, you must decide what information to use for indexing ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.