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 other similar 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 sometimes uses collection classes to mean classes that group things together.

This chapter describes the Collection class, as well as other collection classes.

One of the most basic Visual Basic entities that groups objects is an array. An array stores data values or references to objects in a simple block of memory with one entry directly following another. The Array class provides some special methods for manipulating arrays (such as reversing, sorting, or searching an array).

The Collection class provides a few specific features for working with its group of objects. It enables you to add an item to the Collection, optionally specifying a key for the item. You can then search for the item or remove the item using its key or its index in 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.