日期:2014-05-17 浏览次数:21350 次
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
    class OneToThree : IEnumerable<int>
    {
        public class OneToThreeEnumerator : IEnumerator<int>, IEnumerator
        {
            private int _current = 0;
            public int Current
            {
                get { return _current; }
            }
            public void Dispose()
            {
                //这里我们不需要清理
            }
            object System.Collections.IEnumerator.Current
            {
                get { return _current; }
            }
            public bool MoveNext()
            {
                _current++;
                return _current <= 3;
            }
            public void Reset()
            {
                _current = 0;
            }
        }
        public IEnumerator<int> GetEnumerator()
        {
            return new OneToThree.OneToThreeEnumerator();
        }
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return new OneToThree.OneToThreeEnumerator();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            foreach (int x in new OneToThree())
            {
                Console.WriteLine(x);
            }
        }
    }
}