Unnamed
public text v1 · immutableusing 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