[Mono-list] Iterator hello world.

Jonathan Pryor jonpryor@vt.edu
07 May 2003 10:25:49 -0400

On Wed, 2003-05-07 at 04:56, Erik Bågfors wrote:
<snip content="iterator stuff"/>
Miguel can better answer the iterator question.

> In ruby you also have blocks which could be viewed as anonymous
> methods.  For example you could write this
> DoTimes(3) {|x| print(x) }
> I think I read that something like that was about to show up in C#? Am I
> correct?
> /Erik

Anyonymous methods/closures have been proposed for the next version of
C#.  It builds off the delegate mechanism -- the anonymous method is
turned into a class+function, and a delegate to the function is
returned.  You can also refer to class members & local variables, as
with full closures.

The C# version of your example could be:

	delegate void DoTimesBlock (int n);

	public static void DoTimes (int n, DoTimesBlock b) {
		for ( ; n > 0; --n)
			b (n);

	public static void Main () {
		DoTimes (3, new DoTimesBlock (n) {
			Console.WriteLine (n);

Of course, anonymous methods haven't been finalized, so things may

 - Jon