Pages

VB .NET New Logical Operators AndAlso and OrElse

Vb.Net has introduced two new logical operators AndAlso and OrElse.

These operators basically works like And and Or of VB6.0

The speciality of this the performance of the operators, consider a statement involving two conditions.

if ((2>3) AndAlso (4>3)) Then
'...
'Body of the section
'...
End If


Here, In the statement the first condition is false, let the second condition may true or false, the if block will not go to the then section , since we are using And operator. so either checking or not checking the second condition doesn't have a effect here, so the New Operator AndAlso stops checking the second condition and proceeds. this increases the performance in Logic and efficiency in Code.

Similarly the operator OrElse works in the same manner.

if ((2<3) OrElse (4>3)) Then
'...
'Body of the section
'...
End If


Here, the first condition is true, so no verification of second condition is not required as we are using the Or operator, so it skips the second condition and proceeds.

Thanks to the Creators...

No comments:

Post a Comment