static void Main(string[] args)
        {
            ConcreteAggregate passengers = new ConcreteAggregate();

            passengers[0] = "大鸟";
            passengers[1] = "小菜";
            passengers[2] = "行李";
            passengers[3] = "老外";
            passengers[4] = "公司内部员工";
            passengers[5] = "小偷";

            Iterator iPassenger = new ConcreteIterator(passengers);

            //object item = iPassenger.First();
            while (!iPassenger.IsDone())
            {
                Console.WriteLine("{0}请买票", iPassenger.CuurentItem());
                iPassenger.Next();
            }

            Iterator iPassengerDesc = new ConcreteIteratorDesc(passengers);

            while (!iPassengerDesc.IsDone())
            {
                Console.WriteLine("{0}请买票", iPassengerDesc.CuurentItem());
                iPassengerDesc.Next();
            }
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            var aggregate = new ConcreteAggregate
            {
                [0] = "大鸟",
                [1] = "小菜",
                [2] = "行李",
                [3] = "老外",
                [4] = "公交员工",
                [5] = "小偷"
            };

            Console.WriteLine("ConcreteIterator:");
            Iterator iterator = new ConcreteIterator(aggregate);

            do
            {
                Console.WriteLine($"{iterator.CurrentItem()} 请买车票");
                iterator.Next();
            } while (!iterator.IsDone());

            Console.WriteLine("ConcreteIteratorDesc:");
            Iterator iteratorDesc = new ConcreteIteratorDesc(aggregate);

            do
            {
                Console.WriteLine($"{iteratorDesc.CurrentItem()} 请买车票");
                iteratorDesc.Next();
            } while (!iteratorDesc.IsDone());

            Console.ReadLine();
        }