O'Reilly logo

Visual Basic 2012 Programmer's Reference by Rod Stephens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

COLLECTIONS

The Visual Basic collection classes basically hold items and don’t provide a lot of extra functionality. Other classes described later in this chapter provide more features.

The following sections describe the simple collection classes in Visual Basic: ArrayList, StringCollection, and NameValueCollection. They also describe strongly typed collections that you can build to make code that uses these classes a bit easier to debug and maintain.

ArrayList

The ArrayList class is a resizable array. You can add and remove items from any position in the list and it resizes itself accordingly. The following table describes some of the class’s more useful properties and methods.

PROPERTY/METHOD PURPOSE
Add Adds an item at the end of the list.
AddRange Adds the items in an object implementing the ICollection interface to the end of the list.
BinarySearch Returns the index of an item in the list. The items must implement the IComparable interface, or you must provide the Sort method with an IComparer object.
Capacity Gets or sets the number of items that the list can hold.
Clear Removes all of the items from the list.
Contains Returns True if a specified item is in the list.
CopyTo Copies some of the list or the entire list into a one-dimensional Array object.
Count Returns the number of items currently in the list. This is always less than or equal to Capacity.
GetRange Returns an ArrayList containing the items in part of the list.
IndexOf Returns the zero-based ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required