Without doing anything special for a reference type, Equals()
would mean reference equality (i.e. same object). If I choose to override Equals()
f
Yes, deciding the right rules for this is tricky. There is no single "right" answer here, and it will depend a lot on both context and preference Personally, I rarely bother thinking about it much, just defaulting to reference equality on most regular POCO classes:
Person
as a dictionary-key / in a hash-set is minimal
int Id
as the key in a dictionary (etc) anywayx==y
gives the same result whether x
/y
are Person
or object
, or indeed T
in a generic methodEquals
and GetHashCode
are compatible, most things will just about work out, and one easy way to do that is to not override themNote, however, that I would always advise the opposite for value-types, i.e. explicitly override Equals
/ GetHashCode
; but then, writing a struct
is really uncommon