/// <summary> /// /// </summary> /// <param name="args"></param> static void Main(string[] args) { #region 迭代器调用 Iterator iterator; IListCollection list = new ConcreteList(); iterator = list.GetIterTerator(); while (iterator.MoveNext()) { int i = (int)iterator.GetCurrent(); Console.WriteLine($"迭代到的数值:{i.ToString()}"); iterator.Next(); } Console.Read(); #endregion #region 题外话-测试下 yield return; foreach (var item in GetNumbers()) { Console.WriteLine("Main process. item = " + item); } #endregion }
public ConcreteIterator(ConcreteList list) { _list = list; _index = 0; }