Hash quality and stability of String.GetHashCode() in .NET?

前端 未结 5 419
日久生厌
日久生厌 2020-12-31 04:03

I am wondering about the hash quality and the hash stability produced by the String.GetHashCode() implementation in .NET?

5条回答
  •  借酒劲吻你
    2020-12-31 04:44

    I just came across a related problem to this. On one of my computers (a 64 bit one) I had a problem that I tracked down to 2 different objects being identical except for the (stored) hashcode. That hashcode was created from a string....the same string!

    m_storedhash = astring.GetHashCode();

    I dont know how these two objects ended up with different hash codes given they were from the same string however I suspect what happened is that within the same .NET exe, one of the class library projects I depend upon has been set to x86 and another to ANYCPU and one of these objects was created in a method inside the x86 class lib and the other object (same input data, same everything) was created in a method inside the ANYCPU class library.

    So, does this sound plausible: Within the same executable in memory (not between processes) some of the code could be running with the x86 Framework's string.GetHashCode() and other code x64 Framework's string.GetHashCode() ?

提交回复
热议问题