Simple question about the order of an IF statement in C#.NET
if (Company !=null && Company.ID > 0)
{
}
Does C# work from left to right, and therefore make the check on Company.ID valid?
Thanks.
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.
Essentially, yes.
The
ifstatement expects a boolean operator within the parentheses to determine evaluation of the next statement.Using the
&&operator, if the first boolean checkCompany !=nullis false, it will statement returning false, and not execute the other (Company.ID > 0).Also (for reference), using the
||operator will return true after the first statement if it is true and not evaluate the second.