what is different between equals and referenceequals ?

phicha

Well-known member
Joined
May 11, 2009
Messages
45
Programming Experience
Beginner
i read it on internet article already, and tested it already.
but it didnt show any difference.

thanks,
 
Sometimes one want to compare value equality, other times reference equality. These method provide options to do both under various circumstances. By default reference types are compared by reference for both methods, while ReferenceEquals only compares references for any type. A class can override the Equals instance method to provide value equality.
 
phicha said:
i get it,
equals compare value,
reference compare reference and its value.
Nope.
  • Equals(obj,obj) compares (a) references for reference types and (b) values for value types.
  • ReferenceEquals(obj,obj) compares references only, no matter which type.
  • obj.Equals(obj) uses either default Equals(obj,obj) comparison or the custom override that can be anything.
 
Back
Top