S
sjoshi23
Hi All
Can someone clarify what is happening in these 2 code fragments ?
int i=0;
Action b = delegate {i++; Console.WriteLine("Within b() i= +
i.ToString());};
Action<int> a = delegate(int j){ j++; Console.WriteLine("Within a(i) =
" + j.ToString());};
i++;
b();
// i now becomes 2
a(i);
// i is reported as 3 within a
Console.WriteLine("i = " + i.ToString());
// i still shows as 2 ****
So the question is why i changes for b and not for a ?
thanks
Sunit
Can someone clarify what is happening in these 2 code fragments ?
int i=0;
Action b = delegate {i++; Console.WriteLine("Within b() i= +
i.ToString());};
Action<int> a = delegate(int j){ j++; Console.WriteLine("Within a(i) =
" + j.ToString());};
i++;
b();
// i now becomes 2
a(i);
// i is reported as 3 within a
Console.WriteLine("i = " + i.ToString());
// i still shows as 2 ****
So the question is why i changes for b and not for a ?
thanks
Sunit