public CarIterator(CarCollection collection, bool reverse = false) { this._collection = collection; this._reverse = reverse; if (reverse) { this._position = collection.getItems().Count; } }
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); } }