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


using System.Collections;
internal class Program
{
    class MyArray : IEnumerable
    {
        class MyEnumerator : IEnumerator
        {
            public string[] data = { "Tom", "Sam", "Bob" };
            public int index = -1;
            public object Current
            {
                get {
                    if (index >= 0) return data[index];
                    else return null;
                }
            }
        
            public bool MoveNext()       {
                index++;
                if(index >= data.Length)
                    return false;
                return true;
            }
            public void Reset() { index = -1; }
        }
        public IEnumerator GetEnumerator()     {
            return new MyEnumerator();
        }
    }
    private static void Main(string[] args)
    {
        MyArray people = new MyArray();// = { "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(); // сбрасываем указатель в начало массива
    }
}