为什么我们在重写GetHashCode方法时使用^运算符?

时间:2017-05-17 20:34:36

标签: c# .net .net-core

我正在观看视频,我们会覆盖GetHashCode这样的方法:

public override GetHashCode()
{
    return this.Name.GetHashCode() ^ this.Id.GetHashCode();
}

为什么我们这样做是为了获得新的HashCode?那么为什么XOR运算符在这两个变量之间?

以下是视频:

https://youtu.be/XIbBfmsVzpg?list=PL6n9fhu94yhWi8K02Eqxp3Xyh_OmQ0Rp6

时间9:55

0 个答案:

没有答案
相关问题