There are three kinds of arrays:
Dynamic
Fixed-length
Partly on disk
Code
static void RummanJob1(Args _args) { // array declaration example // by Rumman Ansari // A dynamic array of integers int arrayName[]; // A fixed-length real array with 100 elements real arrayName1[100]; // A dynamic array of dates with only 10 elements in memory date arrayName2[,10]; // A fixed length array of NoYes variables with // 100 elements and 10 in memory NoYes arrayName3[100,10]; print "Done."; pause; }
Array Indices
Array indexes begin at 1. The first item in the array is called [1], the second [2], and so on.
The syntax for accessing an array element is:
ArrayItemReference = ArrayVar [ Index ]
where ArrayVar is the identifier of the array, and Index is the number of the array element. Index can be an integer expression.
For example, a[7] accesses item number 7 in array a.
In X++, item zero[0] is used to clear the array! Assigning a value to index 0 in an array resets all elements in the array to the default value. For example,
intArray[0] = 0; //Resets all elements in intArray
Dynamic Arrays
A dynamic array is declared with an empty array option (that is, only square brackets):
//Dynamic array of integers int intArrayName[]; // Dynamic array of variables of type Datatype Datatype arrayVariableName[];
Fixed-length Arrays
A fixed-length array can hold the number of items that is specified in the declaration. Fixed-length arrays are declared like dynamic arrays but with a length option in the square brackets:
boolean boolArray[100]; //Fixed-length array of booleans with 100 items
Partly On Disk Arrays
Partly on disk arrays are declared either as dynamic or fixed-length arrays with an extra option that declares how many items should be held in memory. The other items are stored on disk and automatically loaded when referenced.
//Dynamic integer array with only 100 elements in memory. int arrayVariableName [ ,100]; //Fixed-length string array with 800 elements, and only 100in memory. str arrayVariableName [800, 100]
Comments
Post a Comment