Thursday, 23 October 2008

& or && that is the question!

Using && instead of &.

if (phContent.Controls[0].ID == "ucSwJobs" & ((SWJobs)phContent.Controls[0]).CheckForCheckedJobs())
{
ShowMessage("You still have selected jobs in SW Jobs!");
}


If we used & in the above if statement we would get an error because the second evaluation relies on the first one being true. If we used && the first statement would fail and the second statement would throw an error.
By using a double && we stop the second statement being evealuated if the first fails!

No comments:

Free Hit Counter