1

I was watching a video where we override GetHashCode method like this:

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

Why did we do that here to get the new HashCode? so why XOR operator between those two variables?

Here is the video:

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

Time 9:55

Mohammed Noureldin
  • 14,913
  • 17
  • 70
  • 99
  • @Abion47 Except it introduces an undue risk for potential collisions in many contexts, it's just easier to type that methods that actually do it more effectively. – Servy May 17 '17 at 20:36
  • 1
    Related: [What is the best algorithm for an overridden System.Object.GetHashCode?](http://stackoverflow.com/q/263400/11683) – GSerg May 17 '17 at 20:40

0 Answers0