C# ArrayList GetEnumerator()

Description

ArrayList GetEnumerator() returns an enumerator for the entire ArrayList.

Syntax

ArrayList.GetEnumerator() has the following syntax.


public virtual IEnumerator GetEnumerator()

Returns

ArrayList.GetEnumerator() method returns An IEnumerator for the entire ArrayList.

Example

The following example gets the enumerator for an ArrayList, and the enumerator for a range of elements in the ArrayList.


using System;/* www .  jav  a2 s . c o m*/
using System.Collections;

class Program
{
    static void Main(string[] args)
    {
        ArrayList colors = new ArrayList();
        colors.Add("A");
        colors.Add("B");
        colors.Add("C");

        IEnumerator e = colors.GetEnumerator();
        while (e.MoveNext())
        {
            Object obj = e.Current;
            Console.WriteLine(obj);
        }

        Console.WriteLine();

        IEnumerator e2 = colors.GetEnumerator(2, 4);
        while (e2.MoveNext())
        {
            Object obj = e2.Current;
            Console.WriteLine(obj);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack