Compartir a través de


Object.Equals Method (Object, Object)

Determines whether two specified instances (objects) of the Object class are equal.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

Syntax

public static bool Equals (
         ObjectobjA,
         ObjectobjB
)

Parameters

  • objA
    The first object you want to compare.
  • objB
    The second object you want to compare.

Return Value

true if the objA and objB parameters are identical or are both null references; otherwise, false.

Remarks

When using this method, you may get unexpected results if you pass it parameters that are not of type Object. For instance, the following code example does not work as it would in the .NET Framework for the desktop.

      long now = DateTime.Now.Ticks;
      DateTime t1 = new DateTime( now );
      DateTime t2 = new DateTime( now );
      Debug.Assert(t1 == t2); // OK
      Debug.Assert(t1.Equals(t2)); // OK
      Debug.Assert(object.Equals(t1, t2 )); // Throws exception!
    

In the preceding example, the exception would not normally be thrown when using the .NET Framework. However, the .NET Micro Framework does throw an exception because it cannot determine the types of the objects being compared. The .NET Micro Framework functions this way to keep its size small. Implementing the full desktop semantics of this method would significantly increase the size of all objects in all programs for the .NET Micro Framework.

Version Information

Available in the .NET Micro Framework versions 2.0, 2.5, 3.0, 4.0, and 4.1.

See Also

Reference

Object Class
Object Members
System Namespace