[Mono-list] Iterator hello world.

Miguel de Icaza miguel@ximian.com
07 May 2003 00:12:43 -0400


The right way of writing hello world with iterators:

using System.Collections;
using System;
class Hello {

	static IEnumerable GetMessage ()
	{
		yield "Hello";
		yield ", ";
		yield "World";
		yield "\n";
	}

	static void Main ()
	{
		foreach (string s in GetMessage ())
			Console.WriteLine (s);
	}
}

Compile with love and run, but do not forget the -v2 option:

	mcs -v2 hello.cs
	mono hello.exe

Miguel.