public void Main2() { // 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 (object element in collection) { Console.WriteLine(element); } Console.WriteLine("\nReverse traversal:"); collection.ReverseDirection(); foreach (object element in collection) { Console.WriteLine(element); } }
public AlphabeticalOrderIterator(WordsCollection collection, bool reverse = false) { this._collection = collection; this._reverse = reverse; if (reverse) { this._position = collection.getItems().Count; } }
private 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); } }
static void Main(string[] args) { Console.WriteLine("Iterator pattern"); Console.WriteLine("=============="); 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); } //BadConcreteAggregateIzaListOfInt izaListOfInt = new BadConcreteAggregateIzaListOfInt(); //BadIIterator ci = izaListOfInt.Iterator(); //int a = 78; //int b = 98; //ci.Add(a); //ci.Add(b); //Console.WriteLine("Do we have 98? " + ci.Find(b)); }
static void Main(string[] args) { // Клиентский код может знать или не знать о Конкретном Итераторе // или классах Коллекций, в зависимости от уровня косвенности, // который вы хотите сохранить в своей программе. var collection = new WordsCollection(); collection.AddItem("1"); collection.AddItem("2"); collection.AddItem("3"); collection.AddItem("4"); collection.AddItem("5"); collection.AddItem("6"); collection.AddItem("7"); collection.AddItem("8"); collection.AddItem("9"); collection.AddItem("10"); 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); } Console.ReadLine(); }