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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
operator
==callsReferenceEqualson comparing objects, so compare that objects are pointing to the same memory location.Equals, instead, is a just virtual method, so can behave differently for different types, as it can be overriden.For example, for CLR
stringEquals compares content of astringand not a reference, even ifstringis a reference type.