static void Main(string[] args) { Clazz clazz = new Clazz(); clazz.AddStudent(new Student("张三")); clazz.AddStudent(new Student("李四")); clazz.AddStudent(new Student("王五")); System.Collections.IEnumerator enumerator = (clazz as System.Collections.IEnumerable).GetEnumerator(); while (enumerator.MoveNext()) { object current = enumerator.Current; Console.WriteLine(current); } foreach (var item in clazz) { Console.WriteLine(item); } }
/// <summary> /// 对班级的依赖 /// </summary> /// <param name="classToInterator"></param> public ClazzASCIterator(Clazz classToInterator) { this.myclass = classToInterator; }