ArrayList: GetEnumerator

GetEnumerator

Returns an enumerator for an ArrayList.



 Public Function GetEnumerator(
	  Optional ByRef StartIndex As Variant,
	  Optional ByRef Count As Variant ) As Object

Parameters

StartIndex
[ByRef] Optional. Variant. The index in the list to being enumeration.
Count
[ByRef] Optional. Variant. The number of items in the list to enumerate over.

Return Values

Object -  An ArrayList enumerator

Remarks

Example

This example shows several methods of enumerating over an ArrayList object.
Private Sub Main()    Dim list As New ArrayList        list.Add "The"    list.Add "quick"    list.Add "brown"    list.Add "fox"         Display the words using the standard For..Each method.    Console.WriteLine "Using For..Each"    IterateUsingForEach list         Display the words using the enumerator manually.    Console.WriteLine "Using an Enumerator"    IterateUsingEnumerator list         Display a subset of the list using For..Each.    Console.WriteLine "Itertate Subset"    IterateSubset list, 1, 2    End SubPrivate Sub IterateUsingForEach(ByVal list As ArrayList)    Dim word As Variant        For Each word In list        Console.WriteValue vbTab & word    Next word    Console.WriteLineEnd SubPrivate Sub IterateUsingEnumerator(ByVal list As ArrayList)    Dim en As IEnumerator        Set en = list.GetEnumerator    Do While en.MoveNext        Console.WriteValue vbTab & en.Current    Loop    Console.WriteLineEnd SubPrivate Sub IterateSubset(ByVal list As ArrayList, ByVal StartIndex As Long, ByVal Count As Long)    Dim word As Variant        For Each word In list.GetEnumerator(StartIndex, Count)        Console.WriteLine "word is {0}", word    Next wordEnd Sub The following output is produced by this code. Using For..Each     The    quick    brown    fox Using an Enumerator     The    quick    brown    fox Iterate Subset word is quick word is brown

See Also

Class ArrayList Overview ArrayList Properties ArrayList Methods Equals GetHashCode