Book contents
- Frontmatter
- Contents
- Preface
- Introduction
- Chapter 1 Collections
- Chapter 2 Arrays and ArrayLists
- Chapter 3 Basic Sorting Algorithms
- Chapter 4 Basic Searching Algorithms
- Chapter 5 Stacks and Queues
- Chapter 6 The BitArray Class
- Chapter 7 Strings, the String Class, and the StringBuilder Class
- Chapter 8 Pattern Matching and Text Processing
- Chapter 9 Building Dictionaries: The DictionaryBase Class and the SortedList Class
- Chapter 10 Hashing and the HashTable Class
- Chapter 11 Linked Lists
- Chapter 12 Binary Trees and Binary Search Trees
- Chapter 13 Sets
- Chapter 14 Advanced Sorting Algorithms
- Chapter 15 Advanced Data Structures and Algorithms for Searching
- Chapter 16 Graphs and Graph Algorithms
- Chapter 17 Advanced Algorithms
- References
- Index
Chapter 2 - Arrays and ArrayLists
Published online by Cambridge University Press: 11 August 2009
- Frontmatter
- Contents
- Preface
- Introduction
- Chapter 1 Collections
- Chapter 2 Arrays and ArrayLists
- Chapter 3 Basic Sorting Algorithms
- Chapter 4 Basic Searching Algorithms
- Chapter 5 Stacks and Queues
- Chapter 6 The BitArray Class
- Chapter 7 Strings, the String Class, and the StringBuilder Class
- Chapter 8 Pattern Matching and Text Processing
- Chapter 9 Building Dictionaries: The DictionaryBase Class and the SortedList Class
- Chapter 10 Hashing and the HashTable Class
- Chapter 11 Linked Lists
- Chapter 12 Binary Trees and Binary Search Trees
- Chapter 13 Sets
- Chapter 14 Advanced Sorting Algorithms
- Chapter 15 Advanced Data Structures and Algorithms for Searching
- Chapter 16 Graphs and Graph Algorithms
- Chapter 17 Advanced Algorithms
- References
- Index
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
- Data Structures and Algorithms Using Visual Basic.NET , pp. 46 - 71Publisher: Cambridge University PressPrint publication year: 2005