When using an if() statement is it better from a performance perspective to use == or !=
if(object==null)
or
if(object!=null)
Should the statement w/ the highest probability of success be first in the if() sequence?
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.
I just analysed the following code in .NET Reflector:
and here is the resulting IL:
From the above it seems that it makes no difference to performance which if() check you use. But, you could look at it this way – try using the if() check which is most likely to occur. So if the object is rarely going to be null at the point of the if check, then use if(object != null).+