/*
C#: The Complete Reference
by Herbert Schildt
Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Demonstrate an enumerator.
using System;
using System.Collections;
public class EnumeratorDemo {
public static void Main() {
ArrayList list = new ArrayList(1);
for(int i=0; i < 10; i++)
list.Add(i);
// Use enumerator to access list.
IEnumerator etr = list.GetEnumerator();
while(etr.MoveNext())
Console.Write(etr.Current + " ");
Console.WriteLine();
// Re-enumerate the list.
etr.Reset();
while(etr.MoveNext())
Console.Write(etr.Current + " ");
Console.WriteLine();
}
}
|