The Point class is derived from System.Object. : System Object Method « Development Class « C# / C Sharp






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());
    }
}

   
  








Related examples in the same category

1.illustrates some of the System.Object class methodsillustrates some of the System.Object class methods
2.System Functions: LogOff, Restart, Shutdown, Hibernate, Standby
3.Object.Equals Method Determines whether the specified Object is equal to the current Object.
4.override Equals method
5.Build Equals method by using the Equals method from member variables
6.ValueType.Equals
7.Object.GetType Method Gets the Type of the current instance.
8.Object.MemberwiseClone Method Creates a shallow copy of the current Object.
9.Object.ReferenceEquals Method Determines whether the specified Object instances are the same instance.
10.Object.ToString Method Returns a String that represents the current Object.