Export (0) Print
Expand All

Object.ReferenceEquals Method

Determines whether the specified Object instances are the same instance.

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

public:
static bool ReferenceEquals (
	Object^ objA, 
	Object^ objB
)
public static boolean ReferenceEquals (
	Object objA, 
	Object objB
)
public static function ReferenceEquals (
	objA : Object, 
	objB : Object
) : boolean
Not applicable.

Parameters

objA

The first Object to compare.

objB

The second Object to compare.

Return Value

true if objA is the same instance as objB or if both are null references; otherwise, false.

The following code example uses ReferenceEquals to determine if two objects are the same instance.

using namespace System;
int main()
{
   Object^ o = nullptr;
   Object^ p = nullptr;
   Object^ q = gcnew 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

*/

import System.*;

class MyClass
{
    public static void main(String[] args)
    {
        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));
    } //main
} //MyClass

/*

This code produces the following output.

True
True
False

*/

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

*/

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft