|
Lars P. Linden MIS Dept. University of Central Florida |
Lab on Arrays
concepts that are covered:
- Declare an array
- Declare and assign values all in one line
- Upperbound
- Index
- Length
- IndexOutOfRangeException
Array Syntax
This is the syntax.
This is how to declare a one-dimensional array
Doesn't seem like much, right? What is missing here is an exclamation of the stupendous importance of adding those parentheses.
Three Basic Data Structures

Understand in the importance of arrays in terms of different data structures.
Up until now we have dealt with variables that have singular values. Regular variables are atomic. Variables that are arrays contain a series of values.
Upperbound
The first question is: "How many?"
The trick is that upperbound of an array is zero-based.
To create an array of holds 100 values, the upperbound should be 99.
Index
Given an array, you assign values to the memory associated with that array by specifying the index.
Think of the index as the "address" to that memory spot within the array's memory structure.
We call a particular this memory spot an element.
Below is an example. The indexes are 0, 1, and 2
Getting an element from an array
Use the index to obtain the value of an element.
Length of an Array
Often you need to know how many elements an array has.
Use the Length property.
Knowing the length will be important later on when we start changing the size of our arrays.
Using Indexes that Do Not Exist
Here is the primary bug that you want to avoid when you code with arrays.
If you reference an index that does not exist for the array, the program throws an IndexOutOfRangeException

This should be a primary concern when you code with arrays.
Creating an array and assigning values in one statement
If you have the values to be assigned to the array, you can declare the array and assign the values all in one statement.
An example:
Big heads-up. Note that the upperbound is not specified above.
The syntax:
A Concept Map of an Array
Here is an illustration of an array in memory.

Summary of Array Basics
Here is what was covered:
- Declare: Dim arrayName(upperbound) As type
- Data Structure: one variable stores a serial list of values
- Upperbound: zero-based index of last value
- Index: how to specify one element of the array
- Length: ask the array how many elements it has
- IndexOutOfRangeException: what happens if you access an element that doesn't exist
<< back to course home
