8.4. Examples Using Arrays

This section presents several examples that demonstrate the declaration, allocation and initialization of arrays, as well as various common manipulations of array elements. The examples in this section use arrays that contain elements of type Integer.

8.4.1. Allocating an Array

The program in Fig. 8.2 uses the New operator to allocate an array of 10 Integer elements, which are initially zero (the default value for Integer variables). The program displays the array elements in tabular format in a console window.

Figure 8.2. Creating an array.
						1
						' Fig. 8.2: CreateArray.vb
						2
						' Declaring and allocating  an array.
						3
						Module CreateArray
 4
						Sub Main()
 5
						Dim array As Integer() ' declare array variable
						6
						7
						' allocate memory for ...

Get Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition 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.