zoukankan      html  css  js  c++  java
  • 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();
                }
            }
        }
    }
    知行合一
  • 相关阅读:
    async 和 await
    C#中lock死锁
    Attribute特性
    数据库优化
    EF(ORM)
    依赖注入
    面向接口编程
    EF乐观锁与悲观锁
    为什么要使用RESTFUL风格?
    cloudsim 3.0.3下载与安装教程
  • 原文地址:https://www.cnblogs.com/YeYunRong/p/5212291.html
Copyright © 2011-2022 走看看