Chapter 28. Collection Classes

Visual Basic .NET includes a large assortment of pre-built classes that store and manage groups of objects. These collection classes provide a wide variety of different features, so the right class for a particular purpose depends on your application.

For example, an array is good for storing objects in a particular fixed order. An ArrayList enables you to add, remove, and rearrange its objects much more easily than an array does. A Queue lets a program easily add items and remove them in first in, first out order. In contrast, a Stack lets the program remove items in last in, first out order.

This chapter describes these different kinds of collection classes and provides tips for selecting the right one for various purposes.

What Is a Collection?

The word collection means a group of objects that should be kept together. For example, a coin collection is a group of coins that you keep together because they are rare, valuable, or otherwise interesting.

Unfortunately, the idea of a collection is such a useful concept that Visual Basic adopted the word and made a specific class named Collection. The Collection class does keep a group of objects together, but it reserves for its own use the perfect word for these kinds of groups of objects.

That leads to some semantic ambiguity when you talk about collection classes. Do you mean the Collection class? Or do you mean some other class that groups objects? Even the Visual Basic documentation has this problem and ...

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