| Iteration with and without foreach based on the enumerator. | Lecture 8 - slide 16 : 37 Program 4 |
using System;
using System.Collections;
public class app {
public static void Main(){
Interval iv1 = new Interval(14,17);
foreach(int k in iv1){
Console.Write("{0,4}", k);
}
Console.WriteLine();
IEnumerator e = iv1.GetEnumerator();
while (e.MoveNext()){
Console.Write("{0,4}", (int)e.Current);
}
Console.WriteLine();
}
} |