static void Main(string[] args) { // 公車,即聚集物件 ConcreteAggregate aggregate = new ConcreteAggregate(); aggregate[0] = "大鳥"; aggregate[1] = "小菜"; aggregate[2] = "行李"; aggregate[3] = "老外"; aggregate[4] = "巴士內部員工"; aggregate[5] = "小偷"; Iterator iterator = new ConcreteIterator(aggregate); while (!iterator.IsDone()) { Console.WriteLine($"{iterator.CurrentItem()} 請買車票"); iterator.Next(); } Console.WriteLine(); Iterator iterator2 = new ConcreteIteratorDesc(aggregate); while (!iterator2.IsDone()) { Console.WriteLine($"{iterator2.CurrentItem()} 請買車票"); iterator2.Next(); } Console.ReadLine(); }
static void Main(string[] args) { ConcreteAggregate a = new ConcreteAggregate(); a[0] = "张三"; a[1] = "李四"; a[2] = "王二"; a[3] = "哇哈哈"; a[4] = "乐事"; Iterator iterator = new ConcreteIterator(a); while (!iterator.IsDone()) { Console.WriteLine("{0} 请买票", iterator.CurrentItem()); iterator.Next(); } Console.Read(); }
static void Main(string[] args) { ConcreteAggregate a = new ConcreteAggregate(); a[0] = "孙悟空"; a[1] = "猪八戒"; a[2] = "沙僧"; a[3] = "白骨精"; a[4] = "玉帝"; Iterator iterator = new ConcreteIterator(a); object item = iterator.First(); while (!iterator.IsDone()) { System.Console.WriteLine($"{iterator.CurrentItem()}"); iterator.Next(); } }
static void Main(string[] args) { ConcreteAggregate a = new ConcreteAggregate(); a[0] = "大鸟"; a[1] = "大鸟1"; a[2] = "大鸟2"; a[3] = "大鸟3"; a[4] = "大鸟4"; a[5] = "大鸟5"; Iterator i = new ConcreteIterator(a); object item = i.First(); while (!i.IsDone()) { Console.WriteLine("{0} 请买票!", i.CurrentItem()); i.Next(); } Console.Read(); }
private static void ClearImplementationDemo() { var aggregate = new ConcreteAggregate(); aggregate[0] = "Item A"; aggregate[1] = "Item B"; aggregate[2] = "Item C"; aggregate[3] = "Item D"; // Create Iterator and provide aggregate IIterator iterator = new ConcreteIterator(aggregate); Console.WriteLine("Iterating over collection:"); while (!iterator.IsDone()) { Console.WriteLine(iterator.CurrentItem()); iterator.Next(); } }
static void Main(string[] args) { var collection = new ConcreteAggregate(); for (int i = 0; i < 10; i++) { collection.Add($" 1 + {i} = {i + 1}"); } var iterator = new ConcreteIterator(collection); while (!iterator.IsDone()) { Console.WriteLine(iterator.Next()); } Console.WriteLine($"\n Valor da primeira posição: {iterator.First()} \n"); Console.WriteLine($" Valor da ultima posição: {iterator.CurrentPosition()}"); Console.ReadKey(); }
static void Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; ConcreteAggregate a = new ConcreteAggregate(); a[0] = "大神"; a[1] = "小神"; a[2] = "老神"; Iterator i = new ConcreteIterator(a); object item = i.First(); while (!i.IsDone()) { Console.WriteLine($"{i.CurrentItem()} 请买车票"); i.Next(); } Console.ReadKey(); }
static void Main(string[] args) { ConcreteAggregate a = new ConcreteAggregate(); a[0] = "大鸟"; a[1] = "小菜"; a[2] = "行李"; a[3] = "老外"; a[4] = "公交内部员工"; a[5] = "小偷"; Iterator iterator = new ConcreteIterator(a); object item = iterator.First(); while (!iterator.IsDone()) { Console.WriteLine("{0}请买车票!", iterator.CurrentItem()); iterator.Next(); } }
static void Main() { Aggregate a = new ConcreteAggregate(); a[0] = "Item A"; a[1] = "Item B"; a[2] = "Item C"; a[3] = "Item D"; Iterator i = new ConcreteIterator(a); Console.WriteLine("Iterating over collection:"); object item = i.First(); while (!i.IsDone()) { Console.WriteLine(item); item = i.Next(); } Console.ReadKey(); }
static void Main(string[] args) { ConcreteAggregate a = new ConcreteAggregate(); a[0] = "大鸟"; a[1] = "大鸟1"; a[2] = "大鸟2"; a[3] = "大鸟3"; a[4] = "大鸟4"; a[5] = "大鸟5"; Iterator i = new ConcreteIterator(a); object item = i.First(); while (!i.IsDone()) { Console.WriteLine("{0} 请买票!", i.CurrentItem()); i.Next(); } Console.Read(); }
static void Main() { ConcreteAggregate <int> b = new ConcreteAggregate <int>(); b[0] = 1; b[1] = 2; b[2] = 3; b[3] = 4; ConcreteIterator <int> j = new ConcreteIterator <int>(b); Console.WriteLine("Iterating over collection:"); while (!j.IsDone()) { var itemT = j.Next(); Console.WriteLine(itemT); } ; Console.ReadKey(); }
static void Main(string[] args) { ConcreteAggregate a = new ConcreteAggregate(); a[0] = "大鸟"; a[1] = "小菜"; a[2] = "行李"; a[3] = "老外"; a[4] = "公交内部员工"; a[5] = "小偷"; Iterator i = new ConcreteIterator(a); while (!i.IsDone()) { Console.WriteLine("{0} 请买车票!", i.CurrentItem()); i.Next(); } Console.ReadKey(); }
static void Main(string[] args) { ConcreteAggregate a = new ConcreteAggregate(); a[0] = "Abby"; a[1] = "Kuan"; a[2] = "小李"; a[3] = "小王"; a[4] = "小白"; a[4] = "小偷"; List <string> aa = new List <string>(); Iterator i = new ConcreteIterator(a); object item = i.First(); while (!i.IsDone()) { Console.WriteLine($"{i.CurrentItem()}請買票"); i.Next(); } Console.ReadKey(); }