Tag: resharper gethashcode

覆盖GetHashCode()

在本文中 ,Jon Skeet提到他通常使用这种算法来覆盖GetHashCode() 。 public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hash = 17; // Suitable nullity checks etc, of course 🙂 hash = hash * 23 + Id.GetHashCode(); return hash; } } 现在,我已经尝试过使用它了,但是Resharper告诉我,方法GetHashCode()应该只使用只读字段进行散列(尽管它编译得很好)。 什么是一个好的做法,因为现在我不能真正让我的字段是只读的? 我尝试通过Resharper生成这个方法,这是结果。 public override int GetHashCode() { return base.GetHashCode(); } 这没什么贡献,说实话……