The following example demonstrates iterating over an ArrayList. Elements are added to, and removed from the list through the use of the methods and properties in the ArrayList. To iterate over the list, use a For Each statement, which can identify each object in the list in turn.

The initial Count of our list is 0 and its Capacity is 16

After populating our list, its Count is 8 and its Capacity is 16

datatypes of elements in the list:
----------------------------------
System.String
System.Int32
System.String
System.String
System.String
ASP.list_aspx+MyType
System.String
System.String
----------------------------------

Removing the integer object...
Removing the MyType object...
Inserting new object...
After modifying our list, its Count is 7 and its Capacity is 16

The entire list now contains the values:
----------------------------------------
Grapes
Apple
Orange
Banana
Pear
Strawberry
Cherry
----------------------------------------

After removing all elements from our list, its Count is 0 and its Capacity is 16