Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
I don't understand why we supplemented the Equals with GetHashCode. Wasn't Equals perfect for or purpose here?
Equals would always be accurate whereas GetHashCode is only mostly accurate.
Allan Clark10,810 Points
As I understand it, hashcode is used to uniquely identify objects. In the Point example this is pretty trivial as any 2 Points that have the same X and Y values ARE the same point, even if they are stored as completely separate objects in memory. However, if we were thinking about cars for example, we cannot assume two cars with the same values (make, model, color etc) refer to the same instance of a car. In these types of cases, the Equals method will call the GetHashCode method to check if the objects in fact are the same.