xiacy

导航

5.5.2 测试被捕获的变量的行为

string captured = "before x is created";

MethodInvoker x = delegate
{
    Console.WriteLine(captured);
    captured = "changed by x";
};

Console.WriteLine(captured);

captured = "directly before x is invoked";
x();
Console.WriteLine(captured);
captured = "before second invocation";
x();

输出结果为
before x is created

directly before x is invoked

changed by x

before second invocation

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