Array is a data structure that contains a set of variables, which are accessed through calculated indexes. The variables contained in an array, also named the elements of the array, are all of the same type. This type is named the element type of the array.
An array has a rank that determines the number of indexes associated with each array element. The number of array dimensions is also referred to as the rank of the array. An array with one dimension is named a one-dimensional array, an array with multiple dimensions is named a multi-dimensional array.
Each array dimension has length. Dimension length determines an acceptable range of indexes for a given dimension. If no explicit limits are determined for the dimension, and only the length N is set, the indexes may take values from 0 to N – 1 inclusive. For a dimension with the limits N..M, the indexes may take values between N and M.
The total number of array elements is the Cartesian product of the lengths of each dimension. If one or more dimensions of the array have zero length, an array is named empty.
An array can be of any simple type as well as of the String type. If an array has the Object type, its elements can also store other arrays.
Sub ArraySample();
Var
Arr1: Array Of Object; // Dynamic array. Size is determined on initialization
Arr2: array[5] Of Char; // One-dimensional array of 5 elements
Arr3: array[-3..3] Of Integer; // One-dimensional array with elements range from -3 to 3
Arr4: array[3, 3] Of Integer; // Two-dimensional array. Elements range in each dimension is 0..3
Arr5: array[3, 2..4] Of Integer; // Two-dimensional array. Elements ranges: 0..3 and 2..4
Arr6: array[2, ] Of Integer = New Integer[2, 3]; // Two-dimensional array with specified sizes of the first dimension
// Second dimension size is set on initialization
Arr7: array[3, 3, 3] Of Integer; // Three-dimensional array
Begin
End Sub;
Sub ArraySample();
Var
Arr1: array Of Object = New Object[5] = [Integer.MaxValue, "ABC", Null, DateTime.Now, New Integer[5]];
Arr2: array[5] Of char = ['a', 'b', 'c', 'd', 'e'];
Arr3: array[-3..3] Of Integer = [1, 2, 3, 4, 5, 6, 7];
Arr4: array[4, 2] Of Integer = [[1, 2], [3, 4], [5, 6], [7, 8]];
Arr5: array[3, 2..4] Of Integer = [[1, 1, 1], [2, 2, 2], [3, 3, 3]];
Arr6: array[2, ] Of Integer = New Integer[2, 3] = [[1, 2, 3], [4, 5, 6]];
Arr7: array[3, 3, 3] Of Integer =
[[[1, 1, 1], [1, 1, 2], [1, 1, 3]],
[[2, 1, 1], [2, 2, 2], [2, 2, 3]],
[[3, 1, 1], [3, 2, 2], [3, 3, 3]]];
Begin
End Sub;
Sub ArraySample();
Var
Arr: Array[2, 2] Of Integer = [[0, 1], [2, 3]];
ElementValue: Integer;
Begin
// Element access
Arr[0, 0] := Arr[0, 1] + Arr[1, 0];
// Work with array in the For Each cycle
For Each ElementValue In Arr Do
// The ElementValue variable provides array element values
// Traverse is executed by strings from left to right
End For;
End Sub;
See also: