fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static Func<int> GeneraDelegado()
  6. {
  7. int variableLocal = 0;
  8. return delegate () { return variableLocal++;}; // Retorna un closure
  9. }
  10.  
  11. public static void Main()
  12. {
  13. Func<int> natural = GeneraDelegado();
  14.  
  15. Console.WriteLine (natural()); // 0
  16. Console.WriteLine (natural()); // 1
  17. }
  18. }
Success #stdin #stdout 0.03s 33928KB
stdin
Standard input is empty
stdout
0
1