Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My educated guess would be to make things operate like the built in types in .NET do, namely that == should work like reference equality where possible, and that Equals should work like value equality where possible. Consider the actual difference between <code>==</code> and <code>Equals</code>:</p> <pre><code>object myObj = new Integer(4); object myObj2 = new Integer(4); //Note that == is only called if the ref'd objects are cast as a type //overloading it. myObj == myObj2; //False (???) myObj.Equals(myObj2); //True (This call is virtual) //Set the references equal to each other -- note that the operator== //comparison now works. myObj2 = myObj; myObj == myObj2; //True myObj.Equals(myObj2); //True </code></pre> <p>This behavior is of course inconsistent and confusing, particularly to new programmers -- but it demonstrates the difference between reference comparisons and value comparisons.</p> <p>If you follow this MSDN guideline, you are following the guideline taken by important classes such as string. Basically -- if a comparison using <code>==</code> succeeds, the programmer knows that that comparison will always succeed, so long as the references involved don't get assigned to new objects. The programmer need never worry about the contents of the objects being different, because they never will be different:</p> <pre><code>//Mutable type var mutable1 = new Mutable(1); var mutable2 = mutable1; mutable1 == mutable2; //true mutable1.MutateToSomethingElse(56); mutable1 == mutable2; //still true, even after modification //This is consistent with the framework. (Because the references are the same, //reference and value equality are the same.) Consider if == were overloaded, //and there was a difference between reference and value equality: var mutable1 = new Mutable(1); var mutable2 = new Mutable(1); mutable1 == mutable2; //true mutable1.MutateToSomethingElse(56); mutable1 == mutable2; //oops -- not true anymore //This is inconsistent with, say, "string", because it cannot mutate. </code></pre> <p>It boils down to that there's no real technical reason for the guideline -- it's just to remain consistent with the rest of the classes in the framework.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload