E.1. Language Changes in VB.NET 2003Visual Basic .NET 2003 included two changes of note in its implementation of the Visual Basic language. E.1.1. Bit Shift OperatorsThe collection of bitwise operators increased in 2003 with the addition of the bit shift operators, << (Shift Left) and >> (Shift Right). Also added were their assignment operator equivalents, <<= and >>=. These operators are discussed in Chapter 5. E.1.2. Declaration in For LoopsVisual Basic .NET 2002 introduced block-level declaration to the language, allowing you to use Dim statements within an If statement, a loop, or other block constructs and have that variable apply in scope only to that block. The other benefit of such usage was that a local variable could be defined at the moment of its first use in a procedure. However, this was not true for loop variables used to control For statements. In the 2003 release, For statements can now include a declaration for the looping variable directly in the For statement. The new syntax adds an As clause to the loop variable name. The following VB.NET 2002 code: Dim counter As Integer For counter = 1 To 10 MsgBox(counter) Next counter can now be written in VB.NET 2003 as: For counter As Integer = 1 To 10 MsgBox(counter) Next counter As with block variables, these For loop variables have valid scope only within the block (the For statement block, in this case). Also, if you want to add a second loop at the same block level to your code using the same variable name, you must include the As clause to that second loop, as its definition does not carry from one loop to the next. This new syntax can also be used with For Each statements. For Each player As TeamMember In baseballTeam MsgBox(player.Name) Next player |