I have a Symbol entity that when compared to another has this behavior:
- If FileName & FileDate are Equal, return True
- If FileDate is different, then Compare the CRC32 of each and return that Value
I’m wondering how to implement this Equality especially the GetHashCode() in this case.
I’d say (based on my understanding of your example), something like this. You could include a more complex hash code that parallels your FileDate vs CRC32, but really since the common glue is always the FileName you could just use that as your surrogate hash code.
Remember, Equal() objects should never have different hash codes, but !Equal() objects may have the same one (it’s just a potential collision).
Also you’ll want to be careful about the fields that are part of the hash code being mutable, otherwise the hash code of the object can “change” which could be very bad in a Dictionary…