Chapter 9. Arrays, Indexers, and Collections

Most of the examples in previous chapters have dealt with one object at a time. In many applications, however, you will want to work with a group of objects all at the same time. A collection is a container that holds a group of objects. Collections are used to hold all the strings in a listbox, to hold all the employees in a company, to hold all the controls on a page, and so forth. This chapter will review the principal collection types offered by the .NET Framework.

The simplest collection in VB.NET is the array. This chapter examines the Array type in detail and also includes coverage of some of the more complicated collection types, including ArrayList, Collection, Queue, and Stack.

In addition, this chapter introduces the concept of indexers, a feature of VB.NET that makes it possible to create your own classes that can be treated like arrays.

Every collection type has certain shared characteristics. These are captured by the collection interfaces. The .NET Framework provides standard interfaces for enumerating, comparing, and creating collections. This chapter concludes with a discussion of the .NET collection interfaces and an example of how you can implement the collection interfaces in your own classes to give your objects collection semantics.


An array is an indexed collection of objects, all of the same type. In this chapter, you will learn to work with three types of arrays: one-dimensional arrays, multidimensional ...

Get Programming Visual Basic .NET, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.