Unity3D – Game Engine – ArrayLists – JavaScript

You have to know that:

– The ArrayList is a .Net class

– ArrayLists are dynamic in size, so you can add and remove items, and the array will grow and shrink in size to fit.

– ArrayLists are also untyped, so you can add items of any kind, including a mixture of types in the same ArrayList.

– ArrayLists are also similarly more costly when compared to the blazingly fast performance of built-in arrays.

– ArrayLists have a wider set of features compared to JS Arrays, although neither of their feature sets completely overlaps the other.

Basic Declaration & Use:


var myArrayList = new ArrayList();    // declaration
myArrayList.Add(anItem);              // add an item to the end of the array
myArrayList[i] = newValue;            // change the value stored at position i
var thisItem : TheType = myArray[i];  // retrieve an item from position i (note the required casting!)
myArray.RemoveAt(i);                  // remove an item from position i
var howBig = myArray.Count;           // get the length of the array

Original article: http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use?

MSDN docs: http://msdn.microsoft.com/en-us/library/system.collections.arraylist.aspx