If I was looking at the following code as Javascript code, it would make sense...but how is it that the call action() in Main doesn't yield a NullReferenceException for i? Did the Action grab a JavaScript context like thing? Thanx in advance to all.
public class Program
{
static void Main(string[] args)
{
var p = new Program();
var action = p.method();
action();
Console.ReadKey();
}
public Action method()
{
var i = 6;
Action action = () => Console.WriteLine(i);
i++;
return action;
}
}
OUTPUT>>7