2
Answers

IEnumerator.Current Property

Maha

Maha

10y
869
1
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)