示例#1
0
        static void Main(string[] args)
        {
            ConcreteList a = new ConcreteList();
            a[0] = "Item A";
            a[1] = "Item B";
            a[2] = "Item C";
            a[3] = "Item D";

            // Create Iterator and provide List
            BackwardIterator back = new BackwardIterator(a);
            object item = null;
            Console.WriteLine("Iterating over collection: with backward iterator");

            item = back.First();
            while (item != null)
            {
                Console.WriteLine(item);
                item = back.Next();
            }
            Console.WriteLine("");
            // Create Iterator and provide List
            ForwardIterator forward = new ForwardIterator(a);

            Console.WriteLine("Iterating over collection: with forward iterator");

            item = forward.First();
            while (item != null)
            {
                Console.WriteLine(item);
                item = forward.Next();
            }

            // Wait for user
            Console.Read();
        }
示例#2
0
        private void PatternStart()
        {
            Iterator   iterator;
            List <int> _list = new List <int> ();

            _list.Add(2);
            _list.Add(3);
            _list.Add(5);
            IListCollection list = new ConcreteList(_list);

            iterator = list.GetIterator();

            while (iterator.MoveNext())
            {
                int i = (int)iterator.GetCurrent();
                Log.Print(i.ToString());
                iterator.Next();
            }
        }
示例#3
0
 // Constructor
 public BackwardIterator(ConcreteList aggregate)
 {
     this.aggregate = aggregate;
     this.current = aggregate.Count - 1;
 }
示例#4
0
 // Constructor
 public ForwardIterator(ConcreteList aggregate)
 {
     this.aggregate = aggregate;
 }
示例#5
0
 public ConcreteIterator(ConcreteList list)
 {
     _list  = list;
     _index = 0;
 }