import System;
import System.Collections;
// Creates and initializes a new ArrayList.
var myAL : ArrayList = new ArrayList();
myAL.Add( "The" );
myAL.Add( "quick" );
myAL.Add( "brown" );
myAL.Add( "fox" );
myAL.Add( "jumped" );
myAL.Add( "over" );
myAL.Add( "the" );
myAL.Add( "lazy" );
myAL.Add( "dog" );
// Displays the values of the ArrayList.
Console.WriteLine( "The ArrayList initially contains the following values:" );
PrintIndexAndValues( myAL );
// Sorts the values of the ArrayList.
myAL.Sort();
// Displays the values of the ArrayList.
Console.WriteLine( "After sorting:" );
PrintIndexAndValues( myAL );
function PrintIndexAndValues( myList : IEnumerable ) {
var i : int = 0;
var myEnumerator : System.Collections.IEnumerator = myList.GetEnumerator();
while ( myEnumerator.MoveNext() )
Console.WriteLine( "\t[{0}]:\t{1}", i++, myEnumerator.Current );
Console.WriteLine();
}
/*
This code produces the following output.
The ArrayList initially contains the following values:
[0]: The
[1]: quick
[2]: brown
[3]: fox
[4]: jumped
[5]: over
[6]: the
[7]: lazy
[8]: dog
After sorting:
[0]: brown
[1]: dog
[2]: fox
[3]: jumped
[4]: lazy
[5]: over
[6]: quick
[7]: the
[8]: The
*/