To support arrays, the .NET Framework provides the Array
class, which is defined in the System namespace. Based on this, you can
formally use the Array class to create an array. To support the creation
of an array, the Array class is equipped with the CreateInstance() method
that comes in various versions. To create a one-dimensional array, you can use
the following version:

The first argument is used to specify the type of array you
want to create. Since it is declared as Type, you can use the typeof
operator to cast your type.

The second argument specifies the number of items of the
list. The items in an Array-based list use a zero-based
index, meaning that the first item has an index of 0, the second has an index of
1, and so on. Using the Array class, you can create a list of the above item
names as follows:

Creating various lists that would be later connected can be
confusing and even overwhelming, as mentioned earlier.

Practical
Learning: Creating a List Class

Start Microsoft Visual Basic .NET or Visual Studio .NET

To start a new application, on the main menu, click File -> New -> Project...

In the Projects Types list, click Visual Basic Projects

In the Templates list, click Windows Application

In the Name box replace the string with DepartmentStore1

To add a project, on the main menu, click File -> Add Project -> New Project...

In the Project Types list, make sure Visual Basic Projects is selected
In the Templates list, click Class Library (.NET)

Set the Name to StoreItem

Click OK

Change the file as follows:

Public Class CStoreItem
Private nbr As String
Private nm As String
Private sz As String
Private uprice As Double
Public Sub New()
nbr = ""
nm = ""
sz = ""
uprice = 0.0
End Sub
Public Sub CStoreItem(ByVal number As String, ByVal name As String, ByVal size As String, ByVal price As Double)
nbr = number
nm = name
sz = size
uprice = price
End Sub
Public Property ItemNumber() As String
Get
Return nbr
End Get
Set(ByVal Value As String)
nbr = Value
End Set
End Property
Public Property ItemName() As String
Get
Return nm
End Get
Set(ByVal Value As String)
nm = Value
End Set
End Property
Public Property Size() As String
Get
Return sz
End Get
Set(ByVal Value As String)
sz = Value
End Set
End Property
Public Property UnitPrice() As Double
Get
Return uprice
End Get
Set(ByVal Value As Double)
uprice = Value
End Set
End Property
End Class

To create the library, on the main menu, click Build -> Build StoreItem

To get a reference of this library to the department store project, in
Solution Explorer, under DepartmentStore1, right-click References and click
Add Reference...

In the Add Reference dialog box, click the Projects property page and make
sure the StoreItem project is selected:

Click Select and click OK

Display the form of the DepartmentStore1 project

Double-click the body of the form to access its Load event

In the top section of the file, under the Inherits line, type Dim lstItemsInStore As Array

When creating an array that you are not initializing,
you must provide the number of items that the list will contain. This number is
passed inside the variable's parentheses as a constant integer. Here is an
example:

The second number of the declaration and the third argument
of the current CreateInstance() method specify the number of items that
each list would contain. In the above declaration, the number 3 means that each
array will be made of three items.

Based on this, here is an example of declaring a
two-dimensional array using the CreateInstance() method:

To know the total number of items that an array contains,
you can access its Length property. To know the number of items that a
particular list contains, call the Array.GetLength() method and pass the
number corresponding to the array. To know the number of items in the first
list, pass the argument as 0. To know the number of items in the second list,
pass the argument as 1.

Multidimensional Array Creation

Besides the single or two-dimensional, you can create
multidimensional arrays by specifying the number of commas in the square
brackets and specifying the numbers. If you want to
use the Array.CreateInstance() method to create a multidimensional
array, you can call the following version:

With this version of the method, the second argument
specifies the number of arrays that the variable will hold.

If you want to find out the total number of items that an
array contains, access its Length property. To get the number of items
that a particular list contains, you can call the Array.GetLength()
method and pass the number corresponding to the array.

To know the number of lists that an array variable contains,
you can access its Rank property.

Operations on Arrays

Adding Items to an Array

There are two main techniques you can use to
initialize an array. You can create its list of items when declaring the array.
Here is an example:

The Array class also provides its own support for adding
items to an array. This is done using the Array.SetValue() that is
overloaded with various versions. To add a new item to a single-dimensional
array, you can use the following syntax:

Probably the most regularly performed operation on a list
consists of retrieving the values of its members. You access the member
of an array using its index as we saw earlier. To perform the same operation,
the Array class is equipped with the GetValue() method that is overloaded
with a version corresponding to each version of the CreateInstance() and
the SetValue() methods. For example, to access the values stored in a
one-dimensional array, you can call call this version:

Overloads Public Function GetValue(ByVal index As Integer) As Object

The argument is the zero-based index of the member whose
value you want to access. If you pass an invalid value, the computer would throw
an IndexOutOfRangeException exception.

Practical
Learning: Accessing the Members of an Array

In the top section of the file, under the Inherits line, declare the
following variable:

When a new item is added to the array, it assumes the last
position. If you want, you can re-arrange the list in a consecutive order. If
the list is a one-dimensional array made of strings, you can arrange it in
alphabetical order. If it is made of numbers, you can order them in increment or
decrement order. If the list is a two, three, or multi-dimensional array, you
can arrange it based on a list-part of your choice. To support the ability to
re-organize the list, the Array class is equipped with the Sort() method
that is overloaded with as many versions as you can possibly need.

To arrange a single-dimensional array in a consecutive
order, you can call the following version of the Array.Sort() method:

Overloads Public Shared Sub Sort(ByVal array As Array)

To reverse the sequence of items of a one-dimensional array,
you can call the Array.Reverse() method. Its syntax is:

Overloads Public Shared Sub Reverse(ByVal array As Array)

Looking for an Item in an Array

When using a list, you may want to know whether a particular
item exists in the list. There are usually two ways to perform this operation.
You usually can use a loop to scan a list. With
this approach, you navigate through the list by visiting the index of each item
and checking the value of that index. Another solution consists of writing a
function to perform the search. The Array class provides its own support
of both solutions using various methods that can be used to perform this
operation.

The Array.IndexOf() method scans a list by accessing
the index of each item. This method is overloaded with three versions. To apply it
on a single-dimensional array, use the following version:

This method visits each member of the array, looking
for the value. Once it finds value in the array, it stops
and returns the index where the first occurrence of value was found. The IndexOf()
method actually looks for the first occurrence of an item in an array. If you
prefer to get the last occurrence of that item in the array, you can call the Array.LastIndexOf()
method. It also is overloaded in three versions.