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


using System;
using System.Collections;
internal class Program
{

    public class MyList : IEnumerable
    {
        string[] people = { "Tom", "Sam", "Bob" };
        public class MyEnumerator : IEnumerator
        {
            string[] people;
            int index = -1;
            public object Current => people[index];

            public MyEnumerator(MyList list)
            {
                this.people = list.people;
                this.index = people.Length;
            }
            public bool MoveNext()
            {
                index--;
                return index >= 0;
            }

            public void Reset()
            {
                index = people.Length;
            }
        }
        public IEnumerator GetEnumerator()
        {
            return new MyEnumerator(this);
        }
    }
    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(); // сбрасываем указатель в начало массива

    }
}