using System.Collections;
internal class Program
{
class MyArray : IEnumerable
{
class MyEnumerator : IEnumerator
{
}
public IEnumerator GetEnumerator()
{
return new MyEnumerator();
}
}
private static void Main(string[] args)
{
MyArray people;// = { "Tom", "Sam", "Bob" };
//foreach (var item in people){ Console.WriteLine(item);}
IEnumerator peopleEnumerator = people.GetEnumerator(); // получаем IEnumerator
while (peopleEnumerator.MoveNext()) // пока не будет возвращено false
{
string item = (string)peopleEnumerator.Current; // получаем элемент на текущей позиции
Console.WriteLine(item);
}
peopleEnumerator.Reset(); // сбрасываем указатель в начало массива
}
}