Mega Code Archive

 
Categories / C# / Development Class
 

The Point class is derived from System Object

using System; class Point  {     public int x, y;     public Point(int x, int y)      {         this.x = x;         this.y = y;     }          public override bool Equals(object obj)      {         if (obj.GetType() != this.GetType()) return false;         Point other = (Point) obj;         return (this.x == other.x) && (this.y == other.y);     }     public override int GetHashCode()      {         return x ^ y;     }     public override String ToString()      {         return String.Format("({0}, {1})", x, y);     }     public Point Copy()      {         return (Point) this.MemberwiseClone();     } } public sealed class App {     static void Main()      {         Point p1 = new Point(1,2);         Point p2 = p1.Copy();         Point p3 = p1;         Console.WriteLine(Object.ReferenceEquals(p1, p2));         Console.WriteLine(Object.Equals(p1, p2));         Console.WriteLine(Object.ReferenceEquals(p1, p3));         Console.WriteLine("p1's value is: {0}", p1.ToString());     } }