Пример #1
0
        public CarIterator(CarCollection collection, bool reverse = false)
        {
            this._collection = collection;
            this._reverse    = reverse;

            if (reverse)
            {
                this._position = collection.getItems().Count;
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var collection = new CarCollection();

            collection.AddItem("BMW");
            collection.AddItem("Mercedes");
            collection.AddItem("Audi");

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

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

            collection.ReverseDirection();

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