Skip to main content
Fixed a simple typo
Source Link
Toby Speight
  • 88.7k
  • 14
  • 104
  • 327

I think you are missing the point. Different objects can produce same hashcode. This can happen:

obj.EqulasEquals(otherObj)  // false
obj.GetHashCode() == otherObj.GetHashCode() //true

If for some reason you want your Equals methods to return true when hashcodes are equal, then by all means. Make sure to document this behavior though.

However if you want to compare references , then use ReferenceEquals method instead. Hashcode comparison will not work for that scenario, because hashcode equality does not guarantee that object are (reference-)equal.

P.S. Also keep in mind, that hashcodes should not change, otherwise hash-tables might break. Make sure that Id and TypeName are read-only properties.

I think you are missing the point. Different objects can produce same hashcode. This can happen:

obj.Equlas(otherObj)  // false
obj.GetHashCode() == otherObj.GetHashCode() //true

If for some reason you want your Equals methods to return true when hashcodes are equal, then by all means. Make sure to document this behavior though.

However if you want to compare references , then use ReferenceEquals method instead. Hashcode comparison will not work for that scenario, because hashcode equality does not guarantee that object are (reference-)equal.

P.S. Also keep in mind, that hashcodes should not change, otherwise hash-tables might break. Make sure that Id and TypeName are read-only properties.

I think you are missing the point. Different objects can produce same hashcode. This can happen:

obj.Equals(otherObj)  // false
obj.GetHashCode() == otherObj.GetHashCode() //true

If for some reason you want your Equals methods to return true when hashcodes are equal, then by all means. Make sure to document this behavior though.

However if you want to compare references , then use ReferenceEquals method instead. Hashcode comparison will not work for that scenario, because hashcode equality does not guarantee that object are (reference-)equal.

P.S. Also keep in mind, that hashcodes should not change, otherwise hash-tables might break. Make sure that Id and TypeName are read-only properties.

added 88 characters in body
Source Link
Nikita B
  • 13.1k
  • 1
  • 26
  • 57

I think you are missing the point. Different objects can produce same hashcode. This can happen:

obj.Equlas(otherObj)  // false
obj.GetHashCode() == otherObj.GetHashCode() //true

If for some reason you want your Equals methods to return true when hashcodes are equal, then by all means. Make sure to document this behavior though.

However if you want to compare references , then use ReferenceEquals method instead. Hashcode comparison will not work for that scenario, because hashcode equality does not guarantee that object are (reference-)equal.

P.S. Also keep in mind, that hashcodes should not change, otherwise hash-tables might break. Make sure that Id and TypeName are read-only properties.

I think you are missing the point. Different objects can produce same hashcode. This can happen:

obj.Equlas(otherObj)  // false
obj.GetHashCode() == otherObj.GetHashCode() //true

If for some reason you want your Equals methods to return true when hashcodes are equal, then by all means. Make sure to document this behavior though.

However if you want to compare references , then use ReferenceEquals method instead. Hashcode comparison will not work for that scenario.

P.S. Also keep in mind, that hashcodes should not change, otherwise hash-tables might break. Make sure that Id and TypeName are read-only properties.

I think you are missing the point. Different objects can produce same hashcode. This can happen:

obj.Equlas(otherObj)  // false
obj.GetHashCode() == otherObj.GetHashCode() //true

If for some reason you want your Equals methods to return true when hashcodes are equal, then by all means. Make sure to document this behavior though.

However if you want to compare references , then use ReferenceEquals method instead. Hashcode comparison will not work for that scenario, because hashcode equality does not guarantee that object are (reference-)equal.

P.S. Also keep in mind, that hashcodes should not change, otherwise hash-tables might break. Make sure that Id and TypeName are read-only properties.

added 3 characters in body
Source Link
Nikita B
  • 13.1k
  • 1
  • 26
  • 57

I think you are missing the point. Different objects can produce same hashcode. This can happen:

obj.Equlas(otherObj)  // false
obj.GetHashCode() == otherObj.GetHashCode() //true

If for some reason you want your Equals methods to return true when hashcodes are equal, then by all means. Make sure to document this behavior though.

However if you want to compare references , then use ReferenceEquals method instead. Hashcode comparison will not work for that scenario.

P.S. Also keep in mind, that hashcodes should not change, otherwise hash-tables mymight break. Make sure that Id and TypeName are read-only properties.

I think you are missing the point. Different objects can produce same hashcode. This can happen:

obj.Equlas(otherObj)  // false
obj.GetHashCode() == otherObj.GetHashCode() //true

If for some reason you want your Equals methods to return true when hashcodes are equal, then by all means. Make sure to document this behavior though.

However if you want to compare references , then use ReferenceEquals method instead. Hashcode comparison will not work for that scenario.

P.S. Also keep in mind, that hashcodes should not change, otherwise hash-tables my break. Make sure that Id and TypeName are read-only properties.

I think you are missing the point. Different objects can produce same hashcode. This can happen:

obj.Equlas(otherObj)  // false
obj.GetHashCode() == otherObj.GetHashCode() //true

If for some reason you want your Equals methods to return true when hashcodes are equal, then by all means. Make sure to document this behavior though.

However if you want to compare references , then use ReferenceEquals method instead. Hashcode comparison will not work for that scenario.

P.S. Also keep in mind, that hashcodes should not change, otherwise hash-tables might break. Make sure that Id and TypeName are read-only properties.

Source Link
Nikita B
  • 13.1k
  • 1
  • 26
  • 57
Loading