巢狀作用域各自產生封裝類別,子層引用父層封裝類別實例:
class Test
{
void F()
{
int y = 123;
for (int i = 0; i < 10; i++)
{
int z = i * 2;
D d = delegate { Console.WriteLine(x + y + z); };
}
}
}
class __Locals1 { public Test __this; public int y; }
class __Locals2 { public __Locals1 __locals1; public int z; public void __Method1() { Console.WriteLine(__locals1.__this.x + __locals1.y + z); } }
外層 __Locals1 捕獲 this 與 y;內層 __Locals2 捕獲 z 並引用 __Locals1。