Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you have described is not a bug. <code>GetHashCode()</code> does not guarantee unique hashes for nonequal objects.</p> <p>From <a href="http://msdn.microsoft.com/en-us/library/system.object.gethashcode.aspx" rel="noreferrer">MSDN</a>:</p> <blockquote> <p>If two objects compare as equal, the GetHashCode method for each object must return the same value. However, if two objects do not compare as equal, the GetHashCode methods for the two object do not have to return different values.</p> </blockquote> <p><strong>EDIT</strong></p> <p>While the MSFT .NET implementation of <code>GetHashCode()</code> for <code>Array.IStructuralEquatable</code> obeys the principles in the above MSDN documentation, it appears that the authors <em>did not</em> implement it as intended.</p> <p>Here is the code from "Array.cs":</p> <pre><code> int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) { if (comparer == null) throw new ArgumentNullException("comparer"); Contract.EndContractBlock(); int ret = 0; for (int i = (this.Length &gt;= 8 ? this.Length - 8 : 0); i &lt; this.Length; i++) { ret = CombineHashCodes(ret, comparer.GetHashCode(GetValue(0))); } return ret; } </code></pre> <p>Notice in particular this line:</p> <p><code>ret = CombineHashCodes(ret, comparer.GetHashCode(GetValue(</code><strong>0</strong><code>)));</code></p> <p>Unless I am mistaken, that <code>0</code> was intended to be <code>i</code>. Because of this, <code>GetHashCode()</code> always returns the same value for arrays with the same max(0, n-8th) element, where n is the length of the array. This isn't <em>wrong</em> (doesn't violate documentation), but it is clearly not as good as it would be if <code>0</code> were replaced with <code>i</code>. Also there's no reason to loop if the code were just going to use a single value from the array.</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