Mono Class Library: System.Collections Namespace

System.Collections.ArrayList Class

Implements a variable-size IList that uses an array of objects to store its elements. [Edit]

See Also: ArrayList Members

[System.Runtime.InteropServices.ComVisible(true)]
public class ArrayList : IList, ICloneable

Thread Safety

This class is safe for multiple readers and no concurrent writers.

Remarks

ArrayList implements a variable-size IList that uses an array of objects to store the elements. A ArrayList has a ArrayList.Capacity, which is the allocated length of the internal array. The total number of elements contained by a list is its ArrayList.Count. As elements are added to a list, its capacity is automatically increased as required by reallocating the internal array. [Edit]

Example

The following example shows how to create, initialize, and display the values of a ArrayList.

C# Example
using System; 
using System.Collections; 

public class SamplesArrayList { 

  public static void Main() { 

  // Create and initialize a new ArrayList. 
  ArrayList myAL = new ArrayList(); 
  myAL.Add("Hello"); 
  myAL.Add("World"); 
  myAL.Add("!"); 

  // Display the properties and values of the ArrayList. 
  Console.WriteLine( "myAL" ); 
  Console.WriteLine( "Count: {0}", myAL.Count ); 
  Console.WriteLine( "Capacity: {0}", myAL.Capacity ); 
  Console.Write( "Values:" ); 
  PrintValues( myAL ); 
  } 

public static void PrintValues( IEnumerable myList ) { 

  IEnumerator myEnumerator = myList.GetEnumerator(); 
  while ( myEnumerator.MoveNext() ) 
    Console.Write( " {0}", myEnumerator.Current ); 
    Console.WriteLine(); 
  } 
}

The output is

myAL

Count: 3

Capacity: 16

Values: Hello World !

Requirements

Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0