! (ReferenceEquals ()) vs! = In Entity Framework 4

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;
            // Do stuff like NotifyPropertyChanged
        }
    }
}

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()?

+3
2

:

  • ReferenceEquals() , , ( ).
  • object.Equals() , , ( )
  • ==() . .

, .

+5

== , , ReferenceEquals ,

-3

Source: https://habr.com/ru/post/1749874/


All Articles