String.GetHashCode() returns different values

前端 未结 2 764
甜味超标
甜味超标 2021-02-12 06:02

Why is GetHashCode() returning a different value for the same string? I can\'t describe how to duplicate this, but trust that this is not a practical joke and that the two follo

相关标签:
2条回答
  • 2021-02-12 06:42

    Is it possible that you copied this string from somewhere?

    I had the same problem. I copied the value ans somehow the BOM header is invisible on the first position.

    Try checking the length and you see already a difference. Also you could check byte-by-byte.

    0 讨论(0)
  • According to documentation:

    If two string objects are equal, the GetHashCode method returns identical values. However, there is not a unique hash code value for each unique string value. Different strings can return the same hash code.

    Thus, some other effect must be in play for the two calls to give different results. One theory is that you switched platforms between the calls, from x86 to x64 or vice versa.

    0 讨论(0)
提交回复
热议问题