GetHashCode() gives different results on different servers?

后端 未结 4 793
南笙
南笙 2020-12-01 16:31

I declared a C# line of code like so

int hashcode = \"apple\".GetHashCode();

On my computer, a computer at work, and a friend\'s computer,

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 17:13

    For your custom classes to return a stable hash code you should override the GetHashCode() method or else the GetHashCode method of the Object class will be used, which I think can vary a lot. (Might even be instance specific).

提交回复
热议问题