相关疑难解决方法(0)

为什么'397'用于ReSharper GetHashCode覆盖?

像许多人一样,我使用ReSharper来加速开发过程.当您使用它来覆盖类的相等成员时,它为GetHashCode()生成的代码生成如下所示:

    public override int GetHashCode()
    {
        unchecked
        {
            int result = (Key != null ? Key.GetHashCode() : 0);
            result = (result * 397) ^ (EditableProperty != null ? EditableProperty.GetHashCode() : 0);
            result = (result * 397) ^ ObjectId;
            return result;
        }
    }
Run Code Online (Sandbox Code Playgroud)

当然我有一些自己的成员,但我想知道的是为什么397?

  • 编辑:所以我的问题会更好措辞,因为它是一个特殊的关于397素数除了它是素数?

resharper hash hash-code-uniqueness

145
推荐指数
3
解决办法
2万
查看次数

标签 统计

hash ×1

hash-code-uniqueness ×1

resharper ×1