Advertisement
vencinachev

PointClass

Jan 5th, 2021
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. class Point
  2. {
  3. private int x;
  4. private int y;
  5. private string name;
  6. public int X
  7. {
  8. get
  9. {
  10. return this.x;
  11. }
  12. set
  13. {
  14. this.x = value;
  15. }
  16. }
  17.  
  18. public int Y
  19. {
  20. get
  21. {
  22. return this.y;
  23. }
  24. set
  25. {
  26. this.y = value;
  27. }
  28. }
  29.  
  30. public string Name
  31. {
  32. get
  33. {
  34. return this.name;
  35. }
  36. set
  37. {
  38. this.name = value;
  39. }
  40. }
  41.  
  42. public Point(string name, int x, int y)
  43. {
  44. this.X = x;
  45. this.Y = y;
  46. this.Name = name;
  47. }
  48.  
  49. public override string ToString()
  50. {
  51. return string.Format($"{this.Name}({this.X}, {this.Y})");
  52. }
  53.  
  54. public override bool Equals(object obj)
  55. {
  56. Point p = (Point) obj;
  57. return this.X == p.X && this.Y == p.Y;
  58. }
  59.  
  60. public static bool operator==(Point p1, Point p2)
  61. {
  62. return p1.Equals(p2);
  63. }
  64.  
  65. public static bool operator !=(Point p1, Point p2)
  66. {
  67. return !p1.Equals(p2);
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement