コード例 #1
0
ファイル: Iterator.cs プロジェクト: moonlaughs/AllPatterns
        public static void Run()
        {
            // The client code may or may not know about the Concrete Iterator
            // or Collection classes, depending on the level of indirection you
            // want to keep in your program.
            var collection = new WordsCollection();

            collection.AddItem("First");
            collection.AddItem("Second");
            collection.AddItem("Third");

            Console.WriteLine("Straight traversal:");

            foreach (var element in collection)
            {
                Console.WriteLine(element);
            }

            Console.WriteLine("\nReverse traversal:");

            collection.ReverseDirection();

            foreach (var element in collection)
            {
                Console.WriteLine(element);
            }
        }
コード例 #2
0
ファイル: Iterator.cs プロジェクト: moonlaughs/AllPatterns
        public AlphabeticalOrderIterator(WordsCollection collection, bool reverse = false)
        {
            this._collection = collection;
            this._reverse    = reverse;

            if (reverse)
            {
                this._position = collection.getItems().Count;
            }
        }