All pastes #358566 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-02-16 09:25 UTC
rendered paste body
using System;

class foo
{

	delegate void G (int x);

	static void Main ()
	{
		Works ();
		Fails ();
	}

	static void Works ()
	{
		int i = 0;

		G g = delegate (int x) { Console.WriteLine (i + " " + x); };

		g (1);
		g (2);
		g (3);
		g (4);

		Console.WriteLine (i);
	}

	static void Fails ()
	{
		int i = 0;

		G g = delegate (int x) { i += x; };

		g (1);
		g (2);
		g (3);
		g (4);

		Console.WriteLine (i);
	}
}

0 1
0 2
0 3
0 4
0
10