Static Array
You can create static arrays by using [size]Type
, the size
must be a compile-time known positive integer:
arr: [5]i32 = {1, 2, 3, 4, 5};
You can also let the length of array to be deduced by using [_]Type
:
arr: [_]bool = {true, false, false, true, true, true};
If you want to access the nth elements in the array, you can use arr[index]
:
arr: [5]i32 = {1, 2, 3, 4, 5};
foo := arr[3];
bar := arr[foo];
The array element access is bound-checked when @runtimeSafety
is on.
Fixed-sized Array Members
Name | Type | Description |
---|---|---|
.length() | Const Member Function | Return the length of the array |
.memoryLayout() | Const Member Function | Return the memory layout type of the array |
.size() | ||
.ptr() | ||
.createDynamicArray() |
Multidimension Arrays
Adding multiple square bracket will make a multidimension array, e.g. [1][2][3]i32
will create a 1×2×3 array.
multi_arr: [2][4]i32 = { {1, 2}, {4, 8}, {16, 32}, {64, 128} };
To access the elements in the multidimension array, use [a, b, c...]arr
syntax:
multi_arr: [2][4]i32 = { {1, 2}, {4, 8}, {16, 32}, {64, 128} };
foo := multi_arr[1, 2];
Multidimension Array Members
Name | Type | Description |
---|---|---|