A database is a list of values. The values can be
organized to make it easy to retrieve and optionally manipulate them. A
computer database is a list of values that are stored in the computer,
usually as one or more files. The values can then be accessed when needed.
Probably the most fundamental type of list of values can be created, and
managed, as an array.

Creating an Array

Before creating an array, you must decide what type of
values each element of the array would be. A simple array can be made of
values of primitive types. Here is an example:

An array can also be made of elements that are each a
composite type. That is, each element can be of a class type. Of course,
you must have a class first. You can use one of the many built-in classes
of the .NET Framework or you can create your own class. After creating the
class, you can then use it as the type of the array. Here is an example:

Every array you create is derived from this class. As
a result, all arrays of your program share many characteristics and they
get their foundation from the Array class. Once you declare an
array variable, it automatically has access to the members of the
Array class. For example, instead of counting the number of
elements in an array, you can access the Length property of the
array variable.

In traditional languages, when you declare an array
variable, you must specify the number of elements that the array will
contain. You must do this especially if you declare the variable without
initializing the array.

After declaring the variable, before using the array,
you must initialize it. Otherwise you would receive an error. When
initializing the array, you can only initialize it with the number of
elements you had specified.

One of the most valuable features of the Array
class is that it allows an array to be resized. That is, if you find out
that an array has a size smaller than the number of elements you want to
add to it, you can increase its capacity. To support this, the
Array class is equipped with the static Resize() member
function. Its syntax is:

As you can see, this is a generic member function that
takes two arguments. The first argument is the name of the array variable
that you want to resize. It must be passed by reference. The second
argument is the new size you want the array to have. Here is an example of
calling this member function:

As done previously, you can create an array in a
member function. A disadvantage of this approach is that the array can be
accessed from only the member function (or event) in which it is created.
As an alternative, you can declare an array as a member of a class. Here
is an example:

The advantage of this approach is that you can access
the array from any member of the same class or even from another file of
the same program. After declaring the variable, you can initialize it. You
can do this in a constructor or in an event that would be fired before any
other event that would use the array. This type of initialization is
usually done in a Load event of a form. After initializing the
array, you can then access it in another member function or another event
of the form. Here is an example:

An array can be passed as argument to a member function.
Here is an example:

void ShowStudents(array<CStudent ^> ^ People)
{
}

In the member function, you can use the array as you see
fit. For example you can assign values to the elements of the array. When
calling a member function that is passed an array, you can pass the argument
by reference so it would come back with new values. Here are examples:

A member function can be created to return an array.
When creating the member function, on the left side of the name of the
member function, type the name of the type of value the member function
would return, including the square brackets. In the member function, create
and initialize an array. Before exiting the member function, you must return
the array. Here is an example:

Because an array is primarily a series of objects or
values, there are various pieces of information you would get interested to
get from it. Typical operations include:

Adding elements to the array

Re-arranging the list or the order of elements in the array

Finding out whether the array contains a certain element

If the array contains a certain element, what index that element has

Although you can write your own routines to perform
these operations, the Array class provides most of the
member functions you would need to get the necessary information.

Adding an Element to an Array

We have seen that, using the [] operator, you can add a
new element to an array. Still, to support this operation, the Array
class is equipped with the SetValue() member function that is
overloaded with various versions. Here is an example that adds an element to
the third position of the array:

When the Array::SetValue() member function is
called, it replaces the element at the indicated position.

Getting an Element From an Array

The reverse of adding an item to an array is to retrieve
one. You can do this with the [] operator. To support this operation, the
Array class is equipped with the GetValue() member
function that comes in various versions. When calling this member function,
make sure you provide a valid index, if you don't, you would get an
IndexOutOfRangeException exception.

Checking the Existence of an Element

Once some elements have been added to an array, you can
try to locate one. One of the most fundamental means of looking for an item
consists of finding out whether a certain element exists in the array. To
support this operation, the Array class is equipped with
the Exists() member function whose syntax is:

This is a generic member function that takes two
arguments. The first is the array on which you will look for the item. The
second argument is a delegate that specifies the criterion to apply.

Finding an Element

One of the most valuable operations you can perform on
an array consists of looking for a particular element. To assist you with
this, the Array class is equipped with the Find()
member function. Its syntax is:

This generic member function takes two arguments. The
first argument is the name of the array that holds the elements. The second
argument is a delegate that has the criterion to be used to find the
element.