fork(1) download
  1. using System;
  2. using static System.Console;
  3. using System.Collections.Generic;
  4.  
  5. public class Program {
  6. public static void Main() {
  7. var acoes = new List<Func<int>>();
  8. var a = 0;
  9. for (var i = 0; i < 5; i++) {
  10. a = i;
  11. acoes.Add(() => a * 2);
  12. }
  13. foreach (var acao in acoes) WriteLine(acao());
  14. acoes = new List<Func<int>>();
  15. for (var i = 0; i < 5; i++) {
  16. int b = i;
  17. acoes.Add(() => b * 2);
  18. }
  19. foreach (var acao in acoes) WriteLine(acao());
  20. }
  21. }
  22.  
  23. //https://pt.stackoverflow.com/q/170393/101
Success #stdin #stdout 0.02s 15988KB
stdin
Standard input is empty
stdout
8
8
8
8
8
0
2
4
6
8