C#IEnumerator.MoveNext 方法 ,

将枚举数推进到集合的下一个元素。

命名空间: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();
            }
        }
    }
}