<  Day Day Up  >  

This chapter covered the operations that can be performed on the fundamental and user -defined types. The next chapter continues this discussion by covering the statements that can be used to act on types and operators.

Here are some points to consider.

  • It is preferable to use parentheses to clarify how an operation is to be performed rather than relying on the precedence and associativity of operators. It is easy to forget the precedence order of the operators!

  • In previous versions, operations on String and the numeric types resulted in a String value, the exact opposite of what happens in Visual Basic .NET. The behavior was changed because many programmers did not expect 1 + "2" to result in "12" .

  • Unlike in previous versions, dividing by zero with the floating-point division operator will produce the value NaN (Not a Number) instead of a division-by-zero exception. (Handling exceptions is covered in Chapter 7.)

  • Text comparisons are significantly slower than binary comparisons because they require looking up information about the current culture. Unless culture-sensitive comparisons are needed, binary comparisons are recommended.

  • The + operator can also be used to concatenate strings. However, because of the possible confusion between concatenating strings ("1" + "2" = "12") and adding numbers (1 + "2" = 3), the & operator should always be used to concatenate strings.

  • Using TypeOf to determine the exact value of a type will be much faster at runtime than attempting to convert the value and handling a resulting exception.

 <  Day Day Up  >  

The Visual Basic .NET Programming Language
The Visual Basic .NET Programming Language
ISBN: 0321169514
EAN: 2147483647
Year: 2004
Pages: 173
Authors: Paul Vick

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: