Click or drag to resize

ArrayNewT Function (Long)

X#
Create an uninitialized array with the specified number of elements and dimensions.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION ArrayNew<T>(
	wElementList AS LONG
)
 AS ARRAY OF<T>
Request Example View Source

Parameters

wElementList
Type: Long
A comma-separated list representing the number of elements in each dimension.
If more than one element number is specified, a multidimensional array is created with the number of dimensions equal to the number of arguments in wElementList.

Type Parameters

T
The type of the array elements

Return Value

Type: Array OfT
An array of specified dimensions.
Remarks
In X#, there are several ways to create an array: Declare an array using a declaration statement such as LOCAL or STATIC. Create an array using a PRIVATE or PUBLIC statement. Assign a literal array to an existing variable. Use the ArrayNew() function.
ArrayNew() has the advantage that it can create arrays within expressions or code blocks. You can also use the ArrayBuild() function to create empty arrays, the ArrayCreate() function to create one-dimensional arrays, or ArrayInit() to create initialized arrays.
Examples
This example creates a one-dimensional array of five elements using the ArrayNew() function, then shows the equivalent action by assigning a literal array of NIL values:
X#
1LOCAL aArray AS ARRAY
2aArray := ArrayNew(5)
3aArray := {NIL, NIL, NIL, NIL, NIL}
This example shows three different statements which create the same multidimensional array:
X#
1aArray := ArrayNew(3, 2)
2aArray := {{NIL, NIL}, {NIL, NIL}, {NIL, NIL}}
3aArray := {ArrayCreate(2), ArrayCreate(2), ArrayCreate(2)}
This example creates a multidimensional array:
X#
1aArray := ArrayNew(3, 2, 5)
See Also