Changes to Operators

Team-Fly    

 
Visual Basic .NET Unleashed
By Paul Kimmel
Table of Contents
Appendix A.  VB6 Programming Element Changes in VB .NET

Changes to Operators

Operators have undergone some changes in Visual Basic .NET, too. This section describes some changes to existing operators and the introduction of a few new operators in Visual Basic .NET.

Equivalence and Implication Operators

The equivalence operator Eqv and the implication operator Imp are not supported in Visual Basic .NET. Where you would have used Eqv operations in VB6, replace the Eqv operator with the equals operator =. Where implication operations made sense in VB6, substitute Imp operations with Not and Or combined.

Implication is equivalent to (Not A) Or B. That is, negate proposition A and Or the result with proposition B.

And, Or, Xor, and Not

Early Beta builds of Visual Basic .NET had removed the bitwise behavior of And, Or, Xor, and Not in Visual Basic .NET. You may have heard that bitwise behavior in And, Or, Xor, and Not had been removed, leaving only logical operator behavior. By Beta 2, build 9254, Microsoft had restored bitwise behavior in And, Or, Xor, and Not and removed the planned operators BitAnd, BitOr, BitXor, and BitNot.

According to Microsoft's Ari Bixhorn, VB6 bitwise and logical operations were restored to And, Or, Xor, and Not and will be there when you get your copy of Visual Studio .NET. This means that the four operators will perform bitwise operations on integral types and logical (or Boolean) operations on logical predicates.

As a reminder, Boolean operations evaluate predicates to determine whether a proposition is True or False. Bitwise operations evaluate the individual bits of each operand. True Or False is an example of Boolean evaluation, and 1 And 2 is an example of a bitwise operation.

Short-Circuit Evaluations

Another planned change was rolled back as of Beta 2. Microsoft had planned to short-circuit Boolean evaluations, resulting in more efficient code. However, because of some influential customers, short-circuiting was rolled back and two new operators were added: AndAlso and OrElse.

A short-circuited evaluation is one that stops evaluating as soon as the result of the proposition can be determined. For example, False And anything yields False regardless of the value of the second predicate. Short-circuiting can safely yield False without evaluating the second predicate.

Some programmers write evaluations that have side effects. A side effect usually happens as a result of one or more predicates being the result of a function that performs some action too. If the Boolean operation short-circuits, the side effect may not occur, breaking code that uses side effects. Refer to the example in the section "Boolean Evaluations Are Not Short-Circuited" in Chapter 2 for a discussion of the impact short-circuited evaluations can have on the behavior of code.

If you want to write And or Or operations that do short-circuit, and produce more efficient code, use AndAlso where you would use And and OrElse where you would use Or. AndAlso and OrElse were introduced when short-circuiting was removed from logical evaluations.


Team-Fly    
Top
 


Visual BasicR. NET Unleashed
Visual BasicR. NET Unleashed
ISBN: N/A
EAN: N/A
Year: 2001
Pages: 222

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net