@manpage Arrays ### Arrays An array is a linear sequence of values that can be addressed using one or more integer indices. Each array has an associated element type. That is, the type of the values actually stored in the array. An array's element type is a purely static property. It is only known at compile time so arrays cannot be 'cast' to different array types at runtime. Array variables are declared using the syntax: _ElementType_`[`[`,`...]`]` An array can be multidimensional, in which case the '[]' will contain 1 or more commas. Here are some example of declaring array variables: ``` Local ints:Int[] 'One dimensional int array. Local map[,] 'Two dimension int array. Local funcs:Int()[] 'One dimensional array of functions of type Int(). Local stacks:Stack[] 'One dimensional array of stacks of type Int. ``` @#### Creating arrays Declaring an array does not actually create an array. To do that you must use the `New` operator. `New` can be used to create either a null intialized or value initialized array. The syntax for creating a null initialized array is: `New` _ElementType_ `[` _Sizes_ `]` ...where sizes is a comma separated sequence of dimension sizes. The syntax for creating a value initialized array is: `New` _ElementType_`[` _Sizes_ `]`( _Element0_`,`_Element1_`,`...etc ) One dimensional arrays can omit sizes when creating a value initialized array: `New` _ElementType_`[` `]`( _Element0_`,`_Element1_`,`...etc ) Here are some examples: ``` Local ints:Int[]=New Int[10] 'Creates a ten element integer array. Local flts:=New Float[]( 1.0,3,5.1,7,9.2 ) 'Creates a 5 element float array initialized to 1.0,3,5.1,7,9.2 Local flts2:=New Float[2,2]( 1,2,3,4 ) 'Creates a 2x2 element float array initialized to 1,2,3,4 ``` @#### Iterating through arrays You can iterate through the elements of an array using `Eachin`, eg: ``` Local arr:=New Int[]( 1,3,5,7,9 ) For Local i:=Eachin arr Print i Next ``` @#### Slicing arrays One dimensional arrays can be sliced using the `Slice` method, eg: ``` Local ints:=New Int[]( 1,3,5,7,9 ) ints=ints.Slice( 1,4 ) 'ints now contains 3,5,7 ``` For more information, see the [[Array.Slice]] API documentation. @#### Resizing arrays One dimensional arrays can be resized using the `Resize` method, eg: ``` Local ints:=New Int[]( 1,2,3 ) ints=ints.Resize( 5 ) 'ints now contains 1,2,3,0,0 ``` Note that resize actually returns a resized *copy* of the input array. The input array is not modified in any way. Multidimensional arrays cannot currently be sliced or resized. For more information, see the [[types.Array.Resize|Array.Resize]] API documentation.