Whats the difference between these two comparison statments?
var result = EqualityComparer<T>.Default.Equals(@this, null);
var result = @this == null;
Obviously the aim is to test whether the object '@this' isnull.
Well it depends on the type of @this
. If it doesn't have an overload of ==
, the second line will just perform a direct reference comparison, whereas the first line will call an overridden Equals
method or an implementation of IEquatable.Equals
.
Any sensible implementation will give the same result for both comparisons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With