Object.ReferenceEquals() Method is used to determine whether the specified Object instances are the same instance or not. This method cannot be overridden. So, if a user is going to test the two objects references for equality and he is not sure about the implementation of the Equals method, then he can call the ReferenceEquals method.
Syntax: public static bool ReferenceEquals (object ob1, object ob2);
ob1: It is the first object to compare.
ob2: It is the second object to compare.
Return Value: This method returns true if ob1 is the same instance as ob2 or if both are null otherwise, it returns false.
Below programs illustrate the use of Object.ReferenceEquals() Method:
null is equal to null
System.Object is not equal to System.Object is equal to System.Object System.Object is not equal to
Note: Here, null will never be printed in the output.
- If both ob1 and ob2 represent the same instance of a value type, the then this method nevertheless returns false.
- If ob1 and ob2 are strings, then this method will return true if the string is interned because this method will never perform a test for value equality.
- Difference between Method Overriding and Method Hiding in C#
- Queue.Contains() Method in C#
- C# | ToCharArray() Method
- Stack.Contains() Method in C#
- Stack.Pop() Method in C#
- TimeSpan.Add() Method in C#
- C# | IsNullOrWhiteSpace() Method
- C# | CompareOrdinal() Method
- C# | SortedDictionary.Add() Method
- C# | StartsWith() Method
- DateTime.Add() Method in C#
- C# | Copy() Method
- C# | ToLower() Method
- C# | ToUpper() Method
- C# | Math.Abs() Method | Set - 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : RohitPrasad3