static void Main(string[] args)
        {
            ConcreteAggegate <string> aggegate = new ConcreteAggegate <string>();

            aggegate[0] = "小明";
            aggegate[1] = "小红";
            aggegate[2] = "小丁";
            aggegate[3] = "小白";


            //顺序读取
            Iterator iterator = new ConcreteIterator <string>(aggegate);

            Console.WriteLine("顺序读取");
            while (iterator.MoveNext())
            {
                Console.WriteLine(iterator.CuurentItem());
            }

            iterator = new ConcreteIteratorDesc <string>(aggegate);

            //逆序读取
            Console.WriteLine("逆序读取");
            while (iterator.MoveNext())
            {
                Console.WriteLine(iterator.CuurentItem());
            }

            Console.ReadKey();
        }
 public ConcreteIteratorDesc(ConcreteAggegate <T> aggegate)
 {
     this._aggegate = aggegate;
     this.count     = aggegate.Count > 0?aggegate.Count:-1;
 }
Example #3
0
 public ConcreteIterator(ConcreteAggegate <T> aggegate)
 {
     this._aggegate = aggegate;
 }