This is some code based on http://unity3d.com/support/documentation/Manual/MonoUpgradeDetails.html and List<T>.Capacity Property (System.Collections.Generic) | Microsoft Learn
It showcases the use of generics in unity js.
import System.Collections.Generic;
function Start ()
{
var list : List.<String>;
list = new List.<String>();
//Capacity is the number of elements that the List<T> can store before resizing is required
//Count is the number of elements that are actually in the List<T>.
Debug.Log("list capacity is " +list.Capacity);
Debug.Log("list count is " +list.Count);
Debug.Log("Adding 4 entries");
list.Add("Generics");
list.Add(" work");
list.Add(" in");
list.Add(" js");
list.Add(" too.");
Debug.Log("Note that now capacity is bigger than count");
Debug.Log("list capacity is " +list.Capacity);
Debug.Log("list count is " +list.Count);
//js cannot have foreach but can use for in
var sentence:String;
for( var word:String in list)
{
sentence +=word;
}
Debug.Log(sentence);
Debug.Log("list.Contains(\"generics\") is " + list.Contains("generics"));
Debug.Log("list.Insert(5, \" Unity js rocks !\");" +" inserts a new item at the end of the list");
list.Insert(5, " Unity js rocks !");
Debug.Log("Let's check it");
sentence = "";
for( var word:String in list)
{
sentence +=word;
}
//For more methods of List check out http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx
//Or google c sharp List
}