Is Object.GetHashCode() unique to a reference or a value?

后端 未结 6 991
南方客
南方客 2020-12-24 12:58

The MSDN documentation on Object.GetHashCode() describes 3 contradicting rules for how the method should work.

  1. If two objects of the same type represent the
6条回答
  •  Happy的楠姐
    2020-12-24 13:38

    A very good explanation on how to handle GetHashCode (beyond Microsoft rules) is given in Eric Lipperts (co. Designer of C#) Blog with the article "Guidelines and rules for GetHashCode". It is not good practice to add hyperlinks here (since they can get invalid) but this one is worth it, and provided the information above one will probably still find it in case the hyperlink is lost.

提交回复
热议问题