If I have an If
statement with 2 conditions - and the first fails, will the 2nd condition even be considered or will it go straight to the else
? So, in the following example, if myList.Count == 0
, will myString
be compared against "value" or will it just straight to else
?
if(myList.Count > 0 && myString.Equals("value"))
{
//Do something
}
else
{
//Do something else
}
It will stop evaluating because you're using the double ampersand && operator. This is called short-circuiting.
If you changed it to a single ampersand:
if(myList.Count > 0 & myString.Equals("value"))
it would evaluate both.