xiacy

导航

5.5.1 定义闭包和不同类型

int outerVariable = 5;
string capturedVariable = "captured";

if (DateTime.Now.Hour == 23)
{
    int normalLocalVariable = DateTime.Now.Minute;
    Console.WriteLine(normalLocalVariable);
}

MethodInvoker x = delegate()
{
    string anonLocal = "local to anonymous method";
    Console.WriteLine("{0} {1} {2}",capturedVariable , anonLocal, outerVariable);
};
x();

 

posted on 2012-05-06 11:46  xiacy  阅读(158)  评论(0编辑  收藏  举报