Maha

Maha

  • NA
  • 0
  • 325.2k

IEnumerator.Current Property

May 14 2014 10:35 AM
http://msdn.microsoft.com/en-us/library/system.collections.ienumerator.current.aspx

This class is given in the above website. Please complete the program.

public class PeopleEnum : IEnumerator
{
public Person[] _people;

// Enumerators are positioned before the first element
// until the first MoveNext() call.
int position = -1;

public PeopleEnum(Person[] list)
{
_people = list;
}

public bool MoveNext()
{
position++;
return (position < _people.Length);
}

public void Reset()
{
position = -1;
}

object IEnumerator.Current
{
get
{
return Current;
}
}

public Person Current
{
get
{
try
{
return _people[position];
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
}



Answers (2)