fork(1) 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. var dict = new Dictionary<int, int>()
  10. {
  11. { 0, 0 },
  12. { 5, 5 },
  13. { 7, 7 }
  14. };
  15.  
  16. Console.WriteLine("Original");
  17. foreach (var kvp in dict)
  18. Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value);
  19.  
  20. foreach (var key in dict.Keys.ToList())
  21. dict[key]++;
  22.  
  23. Console.WriteLine("Increased by 1");
  24. foreach (var kvp in dict)
  25. Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value);
  26.  
  27. dict = dict.ToDictionary(kvp => kvp.Key, kvp => kvp.Value + 1);
  28.  
  29. Console.WriteLine("Increased by 1 again");
  30. foreach (var kvp in dict)
  31. Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value);
  32. }
  33. }
Success #stdin #stdout 0.05s 34136KB
stdin
Standard input is empty
stdout
Original
0 -> 0
5 -> 5
7 -> 7
Increased by 1
0 -> 1
5 -> 6
7 -> 8
Increased by 1 again
0 -> 2
5 -> 7
7 -> 9