Use the inherited Object methods: Equals : System.Object « Class « C# / CSharp Tutorial






using System;

class MainClass
{
    public static void Main(string[] args)
    {
    MainClass c1 = new MainClass();

    MainClass c2 = c1;
    object o = c2;
    
    if(o.Equals(c1) && c2.Equals(o))
      Console.WriteLine("Same instance!\n");

    }
}
Same instance!








7.47.System.Object
7.47.1.Methods of the object Class
7.47.2.Using Methods inherited from the System.Object class: ToString, GetType, GetHashCode, Equals, ReferenceEquals
7.47.3.Static members of System.Object: object.Equals
7.47.4.Static members of System.Object: object.ReferenceEquals
7.47.5.Call object.Equals to compare objects
7.47.6.Use the inherited Object methods: Equals