Use a Hashtable Instead of a Generic Collection


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


Use the System.Collections.Hashtable type.


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 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.