General advice and guidelines on how to properly override object.GetHashCode()

前端 未结 11 1677
终归单人心
终归单人心 2020-12-01 00:09

According to MSDN, a hash function must have the following properties:

  1. If two objects compare as equal, the GetHashCode method for each object m

11条回答
  •  情歌与酒
    2020-12-01 00:43

    What fields to base the hash code upon? If it should only be on immutable fields, what if there are only mutable ones?

    It doesn't need to be based only on immutable fields. I would base it on the fields that determine the outcome of the equals method.

提交回复
热议问题