Exemplo n.º 1
0
        static void Main(string[] args)
        {
            ConcreateAggregate a = new ConcreateAggregate();

            a[0] = "A";
            a[1] = "B";
            a[2] = "C";

            // Iterator i = new ConcreateIterator(a);
            Iterator i = new ConcreateIteratorDesc(a);

            object item = i.First();

            while (!i.IsDone())
            {
                Console.WriteLine($"Hi {i.CurrentItem()}");
                i.Next();
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            ConcreateAggregate concreateAggregate = new ConcreateAggregate();

            for (int i = 0; i < 10; i++)
            {
                concreateAggregate[i] = new Random().Next();
            }

            //Iterator iterator=new ConcreateIterator(concreateAggregate);
            Iterator iterator = concreateAggregate.CreateIterator();
            object   item     = iterator.First();

            while (!iterator.IsDone())
            {
                Console.WriteLine(iterator.CurrentItem());
                iterator.Next();
            }

            Console.ReadKey();
        }
 /// <summary>
 /// 初始化迭代器
 /// </summary>
 /// <param name="aggregate">需要被迭代的具体集合</param>
 public ConcreateIterator(ConcreateAggregate aggregate)
 {
     this._aggregate = aggregate;
 }