private static void ClearImplementationDemo() { var aggregate = new ConcreteAggregate(); aggregate[0] = "Item A"; aggregate[1] = "Item B"; aggregate[2] = "Item C"; aggregate[3] = "Item D"; IIterator iterator = new ConcreteIterator(aggregate); Console.WriteLine("Iterating over collection:"); while (!iterator.IsDone()) { Console.WriteLine(iterator.CurrentItem()); iterator.Next(); } }
// Start is called before the first frame update void Start() { ConcreteAggregate a = new ConcreteAggregate(); a[0] = "大鸟"; a[1] = "小菜"; a[2] = "行李"; Iterator i = new ConcreteIterator(a); object item = i.First(); while (!i.IsDone()) { Debug.Log(i.CurrentItem() + "来了"); i.Next(); } }
public static void IteratorPattern() { ConcreteAggregate a = new ConcreteAggregate(); a[0] = "张三"; a[1] = "李四"; a[2] = "王五"; a[3] = "赵六"; ConcreteIterator i = new ConcreteIterator(a); object item = i.First(); while (!i.IsDone()) { Console.WriteLine($"{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(); } }
//迭代器 public static void testIterator() { ConcreteAggregate a = new ConcreteAggregate(); a[0] = "大鸟"; a[1] = "小菜"; a[2] = "行李"; a[3] = "老外"; a[4] = "公交内部员工"; a[5] = "小偷"; Iterator i = new ConcreteIterator(a); //Iterator i = new ConcreteIteratorDesc(a); object item = i.First(); while (!i.IsDone()) { Console.WriteLine("{0} 请买车票!", i.CurrentItem()); i.Next(); } Console.Read(); }