Advertisement
Qrist

Equal override C#

Dec 2nd, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.53 KB | None | 0 0
  1. namespace ObjectMethods
  2. {
  3.     class Point
  4.     {
  5.         public int X { get; set; }
  6.         public int Y { get; set; }
  7.  
  8.         public Point(int x, int y)
  9.         {
  10.             X = x;
  11.             Y = y;
  12.         }
  13.  
  14.         public override bool Equals(object obj)
  15.         {
  16.             if (obj == null || this.GetType() != obj.GetType())
  17.             {
  18.                 return false;
  19.             }
  20.  
  21.             Point point = obj as Point;
  22.             return (this.X == point.X) && (this.Y == point.Y);
  23.         }
  24.  
  25.     }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement