fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. int [] arr = { 3, 2, 1, 6, 5, 6 };
  10. var closures = new List<Action>();
  11. foreach (var i in arr)
  12. {
  13. var j=i;
  14. closures.Add(() => Console.WriteLine(j));
  15. }
  16.  
  17. foreach (var run in closures)
  18. run();
  19. }
  20. }
Success #stdin #stdout 0.03s 33832KB
stdin
Standard input is empty
stdout
3
2
1
6
5
6