將枚舉數推進到集合的下一個元素。
命名空間: System.Collections
程序集: mscorlib(mscorlib.dll 中)
語法:
bool MoveNext()
返回值
Type: System.Boolean
如果枚舉數已成功地推進到下一個元素,則為 true;如果枚舉數傳遞到集合的末尾,則為 false。
// When you implement IEnumerable, you must also implement IEnumerator.
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();
}
}
}
}
