Call object.Equals to compare objects : System.Object « Class « C# / CSharp Tutorial






public class MainClass
{
   static bool TestForEquality( object obj1, object obj2 )
   {
      if( obj1 == null )
      {
         return false;
      }

      return obj1.Equals( obj2 );
   }

   static void Main()
   {
      object obj1 = new System.Object();
      object obj2 = null;

      System.Console.WriteLine( "obj1 == obj2 is {0}", TestForEquality(obj2, obj1) );
   }
}
obj1 == obj2 is False








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