This documentation is archived and is not being maintained.
Object.ReferenceEquals Method
.NET Framework 1.1
Determines whether the specified Object instances are the same instance.
[Visual Basic] Public Shared Function ReferenceEquals( _ ByVal objA As Object, _ ByVal objB As Object _ ) As Boolean [C#] public static bool ReferenceEquals( object objA, object objB ); [C++] public: static bool ReferenceEquals( Object* objA, Object* objB ); [JScript] public static function ReferenceEquals( objA : Object, objB : Object ) : Boolean;
Parameters
Return Value
true if objA is the same instance as objB or if both are null references; otherwise, false.
Example
[C#, C++, JScript] The following code example uses ReferenceEquals to determine if two objects are the same instance.
[C#] using System; class MyClass { static void Main() { object o = null; object p = null; object q = new Object(); Console.WriteLine(Object.ReferenceEquals(o, p)); p = q; Console.WriteLine(Object.ReferenceEquals(p, q)); Console.WriteLine(Object.ReferenceEquals(o, p)); } } /* This code produces the following output. True True False */ [C++] #using <mscorlib.dll> using namespace System; int main() { Object* o = 0; Object* p = 0; Object* q = new Object(); Console::WriteLine(Object::ReferenceEquals(o, p)); p = q; Console::WriteLine(Object::ReferenceEquals(p, q)); Console::WriteLine(Object::ReferenceEquals(o, p)); } /* This code produces the following output. True True False */ [JScript] import System class MyClass { static function Main() { var o = null; var p = null; var q = new Object(); Console.WriteLine(Object.ReferenceEquals(o, p)); p = q; Console.WriteLine(Object.ReferenceEquals(p, q)); Console.WriteLine(Object.ReferenceEquals(o, p)); } } MyClass.Main(); /* This code produces the following output. True True False */
[Visual Basic] No example is available for Visual Basic. To view a C#, C++, or JScript example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard
See Also
Show: