Chapter 16. Using Arrays and Collections

The data types described in previous lessons each hold a single piece of data. A variable might hold an integer, a string, or a point in time.

Sometimes it's convenient to work with a group of related values all at once. For example, suppose you're the CEO of a huge company that just posted huge losses. In that case, you might want to give each hourly employee a 10 percent pay cut and give each executive a 15 percent bonus.

In cases like this, it would be handy to be able to store all the hourly employee data in one variable so you could easily work with it. Similarly, you might like to store the executives' data in a second variable so it's easy to manage.

In this lesson, you learn how to make variables that can hold more than one piece of data. You learn how to make arrays and different kinds of collections such as Lists, Dictionaries, Stacks, and Queues.

This lesson explains how to build these objects and add and remove items from them. Lesson 19 explains how to get the full benefit of them by looping through them to perform some action on each of the items they contain.

ARRAYS

An array is a group of values that all have the same data type and that all share the same name. Your code uses an index, which is an integer greater than or equal to 0, to pick a particular item in the array.

An array is analogous to the mailboxes in an apartment building. The building has a single bank of mailboxes that all have the same street address (the array's name). ...

Get Stephens' Visual Basic® Programming 24-Hour Trainer 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.