using System.Collections;
public static void Main()
Person[] peopleArray = new Person[3]
new Person("John", "Smith"),
new Person("Jim", "Johnson"),
new Person("Sue", "Rabon"),
People peopleList = new People(peopleArray);
foreach (Person p in peopleList)
Console.WriteLine(p.firstName + " " + p.lastName);
public Person(string fName, string lName)
public class People : IEnumerable
private Person[] _people;
public People(Person[] pArray)
_people = new Person[pArray.Length];
for (int i = 0; i < pArray.Length; i++)
IEnumerator IEnumerable.GetEnumerator()
return new PeopleEnum(_people);
public class PeopleEnum : IEnumerator
public PeopleEnum(Person[] list)
return (position < _people.Length);
object IEnumerator.Current
return _people[position];
catch (IndexOutOfRangeException)
throw new InvalidOperationException();