static void Main(string[] args) { MyClass mc = new MyClass(); foreach (var item in mc) // Use the instance of MyClass. { Console.WriteLine(item); } }
static void Main(string[] args) { MyClass mc = new MyClass(); // Calling the iterator method directly. foreach (string item in mc.WriteAndBlack()) { Console.WriteLine(item); } }
static void Main(string[] args) { MyClass mc = new MyClass(); // Use the class object. foreach (string shade in mc) { Console.Write(shade + "\t"); } // Use the class iterator method. foreach (string shade in mc.WriteAndBlack()) { Console.Write(shade + "\t"); } }