Managing Groups of Objects
For many applications, you want to be able to create and manage groups of related objects. There are two ways to group objects: by creating arrays of objects, and by creating collections.
Arrays are relatively inflexible structures. If you want to change the size of the array at run time, you must use the ReDim statement to redeclare it. All members of the array must be of the same type. On the other hand, arrays allow you to sequentially process all your objects, and you can have empty members of an array. For these reasons, arrays are most useful for creating and working with a fixed number of strongly typed objects.
Collections provide a more flexible way of working with groups of objects. A collection is a class, so you must declare a new collection before you can add members to that collection. Unlike arrays, the group of objects you work with can grow and shrink dynamically as the needs of the program change. You can assign a key to any object that you put into a collection so that you can retrieve and manipulate it based on that key.
In This Section
- Creating Arrays of Objects
- Demonstrates how to declare an array and instantiate its members.
- Collections in Visual Basic .NET
- Provides an overview of collections, discussing the Collection class, zero-based and one-based collections, index and key values, and how to add and remove items.
- Creating Collections of Objects
- Describes how to create a collection and use For...Each...Next to process its members.
- The Visual Basic .NET Collection Class
- Discusses the Collection class, what kinds of items you can add to a collection, and how to access the members after adding them.
- Properties and Methods of the Collection Class
- Describes the properties (Count and Item) and methods (Add and Remove) with which you can manipulate items in a Collection object.
- Adding, Deleting, and Retrieving Items from a Collection
- Explains how to add, retrieve, and delete items from a collection.