Comments on: The origin of GetHashCode in .NET https://codingsight.com/the-origin-of-gethashcode-in-net/ Blog for SQL Server DBAs and Developers Thu, 23 Sep 2021 09:47:59 +0000 hourly 1 https://wordpress.org/?v=6.5.2 By: IDisposable https://codingsight.com/the-origin-of-gethashcode-in-net/#comment-47 Sun, 14 Jan 2018 04:18:00 +0000 http://codingsight.com/?p=518#comment-47 Notice the bug in the 64-bit implementation of string’s GetHashCode… which has been there since .Net 2.0 despite being reported before 2.0 release and several times since?

The loop building hash codes terminates if there’s a zero-Char found in the string. Strings in .Net are NOT terminated by null bytes, they are given a length.

This caused all kinds of problems when I first saw code written and tested on 32-bit runtimes get used on the 64-bit runtime, tons of hash collisions because I had synthesized “keys” that used embedded nulls between the concatenated sub-strings. I later swapped to RS (control character 30 decimal)

]]>