Published online by Cambridge University Press: 11 August 2009
The array is the most common data structure and is found in nearly all computer programming languages. Arrays are implemented somewhat differently in VB.NET than in previous versions of Visual Basic because in VB.NET an array is actually an instantiated Array class object. The Array class provides a set of methods for performing tasks such as sorting and searching that programmers had to build by hand in the past.
A new feature in VB.NET is the ArrayList class. An ArrayList is an array that grows dynamically as more space is needed. For situations where you cannot accurately determine the ultimate size of an array, or where the size of the array will change quite a bit over the lifetime of a program, an ArrayList may be a better choice than an array.
In this chapter we'll quickly touch on the basics of using arrays in VB.NET, then move on to more advanced topics, including copying, cloning, testing for equality, and using the static methods of the Array and ArrayList classes.
ARRAY BASICS
An array stores a set of elements ordered by position. The base position, or index, of arrays in VB.NET is zero, which is a big change from previous versions of Visual Basic, since in those versions the array base was actually user-defined. It is quite common to see Visual Basic 6 (or earlier) array declarations like
Dim Sales(1990 To 1999) As Double
where 1990 is the lower bound and 1999 is the upper bound.
To save this book to your Kindle, first ensure [email protected] is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
Find out more about the Kindle Personal Document Service.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.