Arrays

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[5Of Char; // One-dimensional array of 5 elements
    Arr3: array[-3..3Of Integer; // One-dimensional array with elements range from -3 to 3
    Arr4: array[33Of Integer; // Two-dimensional array. Elements range in each dimension is 0..3
    Arr5: array[32..4Of Integer; // Two-dimensional array. Elements ranges: 0..3 and 2..4
    Arr6: array[2, ] Of Integer = New Integer[23]; // Two-dimensional array with specified sizes of the first dimension
                                                     // Second dimension size is set on initialization
    Arr7: array[333Of 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[
5Of char = ['a''b''c''d''e'];
    Arr3: array[-
3..3Of Integer = [1234567];
    Arr4: array[
42Of Integer = [[12], [34], [56], [78]];
    Arr5: array[
32..4Of Integer = [[111], [222], [333]];
    Arr6: array[
2, ] Of Integer = New Integer[23] = [[123], [456]];
    Arr7: array[
333Of Integer =
        [[[
111], [112], [113]],
        [[
211], [222], [223]],
        [[
311], [322], [333]]];
Begin
End Sub;

Sub ArraySample();
Var
    Arr: Array[
22Of Integer = [[01], [23]];
    ElementValue: Integer;
Begin
    
// Element access
    Arr[00] := Arr[01] + Arr[10];
    
// 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:

Fore.NET Language Guide