Arrays

Arrays are data structures that contain a list of objects of the same type. Not to be confused with static class Array.

Arrays are constructed using the new keyword and a list of values in square brackets:

var digits = new [ 1 2 3 4 5 6 7 8 9 0 ]
var words = new [ "simon" "kamina" "yoko" ]

The array type is defined by the type of the first element. Integer values in an array of floats must be converted manually using conversion methods.

Array's length can be determined using the size method:

print digits.size // 10
print words.size // 3

It is possible to instantly create a large array, giving only the value (or set of values), using array multiplication:

var zeros = new [0] * 100 // one hundred zeros in an array
var nums = new [0 1] * 20 // 40 items total, going 0, 1, 0, 1, 0, 1... and so on 

Arrays can be iterated over. Also, the floating point range creates an array.

Last edited Mar 16, 2011 at 11:02 PM by impworks, version 3

Comments

No comments yet.