This documentation is archived and is not being maintained.

Object::Equals Method (Object, Object)

Determines whether the specified object instances are considered equal.

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

public:
static bool Equals(
	Object^ objA, 
	Object^ objB
)

Parameters

objA
Type: System::Object
The first object to compare.
objB
Type: System::Object
The second object to compare.

Return Value

Type: System::Boolean
true if the objects are considered equal; otherwise, false. If both objA and objB are nullptr, the method returns true.

The static Equals method indicates whether two objects, objA and objB, are equal. It also enables you to test objects whose value is nullptr for equality. It compares objA and objB for equality as follows:

  • It determines whether the two objects represent the same object reference. If they do, the method returns true. This test is equivalent to calling the ReferenceEquals method. In addition, if both objA and objB are nullptr, the method returns true.

  • It determines whether either objA or objB is nullptr. If so, it returns false.

  • If the two objects do not represent the same object reference and neither is nullptr, it calls objA.Equals(objB) and returns the result. This means that if objA overrides the Object::Equals(Object) method, this override is called.

The following example illustrates the Equals method and compares it with the ReferenceEquals method.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: