Make Types Equatable
You should override Object.Equals() and also implement the
By default, Equals() on a reference type checks to see if the objects refer to the same
location in memory. This may be acceptable in some circumstances, but often, you’ll
want to provide your own behavior. With value types, the default behavior is to reflect
over each field and do a bit-by-bit comparison. This can have a very negative impact
on performance, and in nearly every case you should provide your own implementation
was a reference type and other was null, the type-safe version of the function would
be called, not the Object version. You also need to call all the base classes in the
hierarchy so they have an opportunity to check their own fields.
There’s nothing stopping you from also implementing IEquatable<string> (or any
other type) on your type—you can define it however you want. Use with caution,
however, because this may confuse people who have to use your code.
|All times are GMT +5.5. The time now is 15:21.|