示例#1
0
		static void Main(string[] args) {
			IAggregate aggregate = new ConcreateAggregate("Item1", "Item2", "Item3", "Item4");
			IIterator iterator = aggregate.CreateIterator();

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

			Console.ReadKey();
		}
示例#2
0
        static void Main(string[] args)
        {
            //迭代器模式

            ConcreateAggregate aggregate = new ConcreateAggregate();

            aggregate[0] = "长腿美女";
            aggregate[1] = "帅哥";
            aggregate[2] = "小偷";
            aggregate[3] = "警察";
            aggregate[3] = "内部员工售票员";

            //Iterator.Base.Iterator iterator = new ConcreteInerator(aggregate);
            Iterator.Base.Iterator iterator = new ConcreteIneratorDesc(aggregate);
            object item = iterator.First();

            while (!iterator.IsDone())
            {
                Console.WriteLine("{0},请您买票!", iterator.CurrentItem());
                iterator.Next();
            }

            Console.Read();
        }
示例#3
0
 public ConcreateIterator(ConcreateAggregate integerList)
 {
     this.integerList = integerList;
     this.index       = 0;
 }