fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Test
  5. {
  6. static void AddAll(ref int x, List<int> values)
  7. {
  8. //values.ForEach(v => x += v); // <-- не скомпилируется
  9. foreach(int v in values) x += v;
  10. }
  11.  
  12. public static void Main()
  13. {
  14. int result = 0;
  15. List<int> l1 = new List<int> { 1, 2, 3 };
  16. List<int> l2 = new List<int> { 4, 5 };
  17. AddAll(ref result, l1);
  18. AddAll(ref result, l2);
  19. Console.WriteLine(result);
  20. }
  21. }
Success #stdin #stdout 0.03s 15080KB
stdin
Standard input is empty
stdout
15