Monday, May 31, 2010

Requirements for overriding GetHashCode

The following are the requirements to remember when  you override GetHashCode System.Object function: 
  • Two equal objects must have equal hash codes
  • The Hash code of a particular object must never change (you might want to cache the result. In NHibernate's case you should use the primary keys to generate it since they do not change)
  • It should not throw exceptions 

That's it. Plain and simple.

Enjoy!

No comments:

Post a Comment