fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Test
  5. {
  6. public Test() {}
  7. public Test(int id)
  8. {
  9. Id = id;
  10. }
  11. public long Id { get; set; }
  12. public override bool Equals(object other)
  13. {
  14. var test = other as Test;
  15. if (test == null) return false;
  16. return test.Id == Id;
  17. }
  18.  
  19. public override int GetHashCode()
  20. {
  21. return Id.GetHashCode();
  22. }
  23.  
  24. public override string ToString()
  25. {
  26. return $"{{ Id: {Id} }}";
  27. }
  28.  
  29. public static void Main()
  30. {
  31. var map = new Dictionary<string, Test>();
  32. var test = new Test(5);
  33. map["hey"] = new Test(0);
  34. map["hey"] = test;
  35. test.Id = 6;
  36. map["hey"] = test;
  37. map["holla"] = new Test(2);
  38. foreach(var pair in map) {
  39. Console.WriteLine("key: {0}, value: {1}", pair.Key, pair.Value);
  40. }
  41. }
  42. }
Success #stdin #stdout 0.03s 14748KB
stdin
Standard input is empty
stdout
key: hey, value: { Id: 6 }
key: holla, value: { Id: 2 }