C# ArrayList GetEnumerator(Int32, Int32)
Description
ArrayList GetEnumerator(Int32, Int32)
returns an enumerator
for a range of elements in the ArrayList.
Syntax
ArrayList.GetEnumerator(Int32, Int32)
has the following syntax.
public virtual IEnumerator GetEnumerator(
int index,
int count
)
Parameters
ArrayList.GetEnumerator(Int32, Int32)
has the following parameters.
index
- The zero-based starting index of the ArrayList section that the enumerator should refer to.count
- The number of elements in the ArrayList section that the enumerator should refer to.
Returns
ArrayList.GetEnumerator(Int32, Int32)
method returns An IEnumerator for the specified range of elements in the ArrayList.
Example
The following example gets the enumerator for an ArrayList, and the enumerator for a range of elements in the ArrayList.
using System;/* w w w. j a v a 2 s . c om*/
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.