Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // 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);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // Клиентский код может знать или не знать о Конкретном
            // Итераторе или классах Коллекций, в зависимости от уровня
            // косвенности, который вы хотите сохранить в своей программе.
            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);
            }
        }
Exemplo n.º 3
0
 public AlphabeticalOrderIterator(WordsCollection collection, bool reverse = false)
 {
     this._collection = collection;
     this._reverse    = reverse;
     if (reverse)
     {
         this._position = collection.getItems().Count;
     }
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            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);
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            var collection = new WordsCollection();

            collection.AddItem("Primeiro");
            collection.AddItem("Segundo");
            collection.AddItem("Terceiro");

            Console.WriteLine("Original");

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

            Console.WriteLine("Ao Contrario");

            collection.ReverseDirection();

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