Prev | Current Page 104 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

You specify the type of data held in an Array as you would
specify the associated type of a template in C++. All you do is simply add the type of the contained data
to the end of the Array type identifier and surround it using left and right angle brackets. For example,
an Array of Int values is initialized like this:
var intArray : Array < Int > ;
(continued)
Chapter 3: Learning the Basics
41
To initialize the data in an Array with literal values, you can supply a literal list contained in square
brackets at the end of the Array declaration, which will pre - populate the Array with the given values:
var intArray : Array < Int > = [3,2,1];
When using an Array, you do not need to specify its size prior to use, as the platforms that will use the
compiled Array are dynamic in length. This means that you can add new items to an Array without
worrying about running out of allocated memory.
There are several types of Array in haXe: Array , List , Hash , and IntHash . Each Array type offers a
slightly varied list of functionality over the other types, but all will prove their purpose in your haXe
applications.


Pages:
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116