using System;
public class Test
{
public static void Main()
{
int variableLocal = 0;
// Captured variable:
Func<int> delegado = delegate() { return variableLocal++;};
Console.WriteLine (delegado()); // 0
Console.WriteLine (delegado()); // 1
Console.WriteLine (variableLocal); // 2
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFRlc3QKewoJcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQoJewoJCWludCB2YXJpYWJsZUxvY2FsID0gMDsKCQkKCQkvLyBDYXB0dXJlZCB2YXJpYWJsZToKCQlGdW5jPGludD4gZGVsZWdhZG8gPSBkZWxlZ2F0ZSgpIHsgcmV0dXJuIHZhcmlhYmxlTG9jYWwrKzt9OwoJCQoJCUNvbnNvbGUuV3JpdGVMaW5lIChkZWxlZ2FkbygpKTsJCS8vIDAKCQlDb25zb2xlLldyaXRlTGluZSAoZGVsZWdhZG8oKSk7CQkvLyAxCgkJQ29uc29sZS5Xcml0ZUxpbmUgKHZhcmlhYmxlTG9jYWwpOwkvLyAyCgl9Cn0=