If a class specifically overrides the behavior defined for Object, ReferenceEquals and == do the same ... compare references.
In property installers, I usually used a template
private MyType myProperty;
public MyType MyProperty
{
set
{
if (myProperty != value)
{
myProperty = value;
}
}
}
However, in the code generated by the Entity Framework, the statement ifis replaced by
if (!ReferenceEquals(myProperty, value))
The use of ReferenceEquals is more explicit (I assume that not all C # programmers know that == does the same, if not overridden).
Is there any difference that eludes me between the two if options? Perhaps they explain what POCO designers can override ==?
In short, if I did not override ==, I will save with! = Instead ReferenceEquals()?