Why does Visual Studio add "-1937169414" to a generated hash code computation?

asked6 years ago
last updated6 years ago
viewed6.6k times
Up Vote12Down Vote

If you use Visual Studio's own refactoring menu to add a GetHashCode implementation to a class like this:

and select the only int property in the class:

it generates this code on .NET Framework:

public override int GetHashCode()
{
    return -1937169414 + Value.GetHashCode();
}

(it generates HashCode.Combine(Value) on .NET Core instead, which I'm not sure if it involves the same value)

What's special about this value? Why doesn't Visual Studio use Value.GetHashCode() directly? As I understand, it doesn't really affect hash distribution. Since it's just addition, consecutive values would still accumulate together.

EDIT: I only tried this with different classes with Value properties but apparently property name affects the number generated. For instance, if you rename the property to Halue, the number becomes 387336856. Thanks to Gökhan Kurt who pointed this out.