fork download
  1. using System;
  2.  
  3. struct Mutable
  4. {
  5. public int X;
  6. public void Mutate() { X = 5; }
  7. }
  8.  
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var coll = new[] { new Mutable() { X = 1 } };
  14. foreach (var m in coll)
  15. {
  16. Action a = () => m.Mutate();
  17. a();
  18. Console.WriteLine(m.X);
  19. }
  20. }
  21. }
Success #stdin #stdout 0.01s 29664KB
stdin
Standard input is empty
stdout
5