private static Action myDelegate()
{
int c = 0;
return delegate
{
c++;
Console.WriteLine(c);
};
}
private static void Main(string[] args)
{
Action p = myDelegate();
p();
p();
p();
Console.Read();
}
这段代码打印1 2 3,这是C#中闭包