O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required