The logical operator And doesn't "short circuit" a conditional expression. In the ff expression:
IF expression1 AND expression2
when expression1 is False, expression2 will still be evaluated even if the overall result of the condition is APPARENTLY False. for example, in the ff code:
If sName IsNot Nothing And Not sName.Equals("") Then
... code here...
End If
the expression [Not sName.Equals("")] will still be evaluated even if the expression [sName IsNot Nothing ] is already False (meaning sName is nothing). This creates a null pointer exception. The solution: use AndAlso instead of And.
Same with Or, if expression1 is already true, expression2 will still be evaluated. use OrElse instead --the 2nd expression will no longer be evaluated when the first expression is already True.
Or don't use And & Or at all, they'll just lead you to sneaky bugs.
I know this is such a trivial info. but sorry, I've been working with VB.net for just 6 months now, which is still interrupted by java work, time to time. so that explains the big fuss :O I was so amazed. omg ang babaw ko! Thanks to my officemates who taught me this. haha!
sorry for the geek post.
1 comment:
hi sis! Grabe, ang geeky nga ng post. hehehe. Pero sobrang nakakarelate ako, since I'm using .NET 2005 ngayon. :)
Post a Comment