Skip to main content Accessibility help
×
Hostname: page-component-76fb5796d-45l2p Total loading time: 0 Render date: 2024-04-27T21:35:06.396Z Has data issue: false hasContentIssue false

Chapter 2 - Arrays and ArrayLists

Published online by Cambridge University Press:  11 August 2009

Michael McMillan
Affiliation:
Pulaski Technical College, Arkansas
Get access

Summary

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.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2005

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org 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.

  • Arrays and ArrayLists
  • Michael McMillan, Pulaski Technical College, Arkansas
  • Book: Data Structures and Algorithms Using Visual Basic.NET
  • Online publication: 11 August 2009
  • Chapter DOI: https://doi.org/10.1017/CBO9780511547010.004
Available formats
×

Save book 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 Dropbox.

  • Arrays and ArrayLists
  • Michael McMillan, Pulaski Technical College, Arkansas
  • Book: Data Structures and Algorithms Using Visual Basic.NET
  • Online publication: 11 August 2009
  • Chapter DOI: https://doi.org/10.1017/CBO9780511547010.004
Available formats
×

Save book to Google Drive

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.

  • Arrays and ArrayLists
  • Michael McMillan, Pulaski Technical College, Arkansas
  • Book: Data Structures and Algorithms Using Visual Basic.NET
  • Online publication: 11 August 2009
  • Chapter DOI: https://doi.org/10.1017/CBO9780511547010.004
Available formats
×