E
Ethan Strauss
Hi,
I have a moderately complex class (about 10 different string and int
type fields along with two different List<string> fields). I want to override
Equals(), so I need to override GetHashCode(). The standard override for
GetHashCode() for something would be to join GetHashCode for each field with
^ (XOR). Right? But, in this case, one of the fields is a "Unique" Identifier
and SHOULD uniquely identify the instance of the class. If that is the case,
is it acceptable to just use the HashCode for that uniqueID field as the
HashCode for the instance? What if there are two different instances with
the same "Unique" identifier, but different contents (which is what I am
looking for with my Equals() override)? If they evaluate to the same HashCode
will that cause major issues?
Thanks!
Ethan
I have a moderately complex class (about 10 different string and int
type fields along with two different List<string> fields). I want to override
Equals(), so I need to override GetHashCode(). The standard override for
GetHashCode() for something would be to join GetHashCode for each field with
^ (XOR). Right? But, in this case, one of the fields is a "Unique" Identifier
and SHOULD uniquely identify the instance of the class. If that is the case,
is it acceptable to just use the HashCode for that uniqueID field as the
HashCode for the instance? What if there are two different instances with
the same "Unique" identifier, but different contents (which is what I am
looking for with my Equals() override)? If they evaluate to the same HashCode
will that cause major issues?
Thanks!
Ethan