public AlphabeticalOrderIterator(LuckyCustomers customerCollection, bool reverse = false) { this._customerCollection = customerCollection; this._reverse = reverse; if (reverse) { this._customerPosition = customerCollection.getItems().Count; } }
static void Main(string[] args) { var collection = new LuckyCustomers(); collection.AddItem("Jane Doe"); collection.AddItem("Jack Sparrow"); collection.AddItem("Adam Smith"); Console.WriteLine("Straight:"); foreach (var element in collection) { Console.WriteLine(element); } Console.WriteLine("\nReverse :"); collection.ReverseDirection(); foreach (var element in collection) { Console.WriteLine(element); } }
public IteratorPatternStrategy() { var collection = new LuckyCustomers(); collection.AddItem("Jane Doe"); collection.AddItem("Jack Sparrow"); collection.AddItem("Adam Smith"); Console.WriteLine("Straight:"); foreach (var element in collection) { Console.WriteLine(element); } Console.WriteLine("\nReverse :"); collection.ReverseDirection(); foreach (var element in collection) { Console.WriteLine(element); } }