实现IEnumerator接口的枚举器类型

class myyield : IEnumerator,IEnumerable
    {
        List items = null;
        int currindex = -1;
        public myyield(List list)
        {
            this.items = list;
        }
        public Object Current
        {
            get
            {
                return items[currindex];
            }
        }

        public bool MoveNext()
        {
            currindex++;
            if (items.Count > currindex)
            {
                return true;
            }
            return false;
        }

        public void Reset()
        {
            currindex = 0;
        }

        public IEnumerator GetEnumerator()
        {
            return this;
        }
    }

你可能感兴趣的:(C#)