Wednesday, January 09, 2013

AndAlso & OrElse Operator

In VB.Net, there are two useful operators AndAlso & OrElse to Replace And & Or operators.

AndAlso & OrElse, operators are works as follows.

Both takes two operators.

When First one evaluated as false, AndAlso will not evaluate the second, as the result will surely result in false.

When First one evaluated as true, OrAlso will not evaluate the second, as the result will surely result in true.

 

This operation helps in one important situation, to check null and evaluate.

obj IsNot null AndAlso obj.Value=”value”

When obj is null, second condition will not be evaluated, and so, it will result in NullReferenceException.

Also, AndAlso and OrElse operators perform well than And and Or operators as the second operant will not be executed based on the result of first operand

No comments:

Post a Comment