SUMMARY

This chapter explained several types of collection classes.

Variable arrays store objects sequentially. They allow fast access at any point in the array. The Array class lets you make arrays indexed with nonzero lower bounds, although they provide slower performance than arrays of variables, which require lower bounds of zero. The Array class provides several useful methods for working with Array objects and normal variable arrays, including Sort, Reverse, IndexOf, LastIndexOf, and BinarySearch.

Collections store data in ways that are different from those used by arrays. An ArrayList stores items in a linked list. That works well for short lists, but slows down when the list grows large. A StringCollection holds a collection of strings. StringCollection is an example of a strongly typed collection (it holds only strings). The NameValueCollection class is a specialized collection that can hold more than one string value for a given key value.

Dictionaries associate key values with corresponding data values. You look up the key to find the data much as you might look up a word in the dictionary to find its definition. The ListDictionary class stores its data in a linked list. It is fast for small data sets but slow when it contains too much data. In contrast a Hashtable has substantial overhead but is extremely fast for large dictionaries. A HybridDictionary acts as a ListDictionary if it doesn’t contain too much data and switches to a Hashtable when it gets too big. The ...

Get Visual Basic 2012 Programmer's Reference 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.