Загрузка данных


using System.Collections;
internal class Program
{
    internal class MyEnumerator : IEnumerator
    {
        string[] people = { "Tom", "Sam", "Bob" };
        int index = -1;
        public object Current => people[index];

        public bool MoveNext()
        {
            index++;
            return index < people.Length;
        }

        public void Reset()
        {
            index = -1;
        }
    }
    class MyList : IEnumerable
    {
        public IEnumerator GetEnumerator()
        {
            return new MyEnumerator();
        }
    }
    private static void Main(string[] args)
    {
        MyList people = new MyList();

        IEnumerator peopleEnumerator = people.GetEnumerator(); // получаем IEnumerator
        while (peopleEnumerator.MoveNext())   // пока не будет возвращено false
        {
            string item = (string)peopleEnumerator.Current; // получаем элемент на текущей позиции
            Console.WriteLine(item);
        }
        peopleEnumerator.Reset(); // сбрасываем указатель в начало массива

    }
}