fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. Dictionary<Coord, string> dict = new Dictionary<Coord, string>();
  9. dict[new Coord(4, 5)] = "Test";
  10. Console.WriteLine(dict[new Coord(4, 5)]);
  11. dict[new Coord(4, 5)] = "Test2";
  12. Console.WriteLine(dict[new Coord(4, 5)]);
  13. }
  14. }
  15.  
  16. public struct Coord : IEquatable<Coord>
  17. {
  18. public int X { get; private set; }
  19. public int Y { get; private set; }
  20.  
  21. public Coord(int x,int y) : this(){ X = x;
  22. Y = y;}
  23.  
  24. //Overloaded operator functuions below
  25. //So I can easily multiply Coords by other Coords and ints and also add Coords together
  26. public static Coord operator *(Coord left, int right)
  27. {
  28. return new Coord(left.X * right, left.Y * right);
  29. }
  30.  
  31. public static Coord operator *(Coord left, Coord right)
  32. {
  33. return new Coord(left.X * right.X, left.Y * right.Y);
  34. }
  35.  
  36. public static Coord operator +(Coord left, Coord right)
  37. {
  38. return new Coord(left.X + right.X, left.Y + right.Y);
  39. }
  40.  
  41. public static Coord operator -(Coord left, Coord right)
  42. {
  43. return new Coord(left.X - right.X, left.Y - right.Y);
  44. }
  45.  
  46.  
  47. public override int GetHashCode()
  48. {
  49. int hash = 17;
  50. hash = hash * 31 + X;
  51. hash = hash * 31 + Y;
  52. return hash;
  53. }
  54.  
  55. public override bool Equals(object other)
  56. {
  57. return other is Coord ? Equals((Coord)other) : false;
  58. }
  59.  
  60. public bool Equals(Coord other)
  61. {
  62. return X == other.X &&
  63. Y == other.Y;
  64. }
  65. }
Success #stdin #stdout 0.03s 34000KB
stdin
Standard input is empty
stdout
Test
Test2