using System;
using System.Collections;
//using System.Linq;
internal class Program
{
public class MyList : IEnumerable
{
internal 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 = new string[list.people.Length];
for (int i = 0; i < list.people.Length; i++)
{
this.people[i] = list.people[list.people.Length - 1 - i];
}
//this.people = list.people.Reverse().ToArray();
}
public bool MoveNext()
{
index++;
return index < people.Length;
}
public void Reset()
{
index = -1;
}
}
public IEnumerator GetEnumerator()
{
return new MyEnumerator(this);
}
}
private static void Main(string[] args)
{
MyList people = new MyList();
IEnumerator peopleEnumerator = people.GetEnumerator();
while (peopleEnumerator.MoveNext())
{
string item = (string)peopleEnumerator.Current;
Console.WriteLine(item);
}
peopleEnumerator.Reset();
}
}