Widening and Narrowing Conversions

With the exception of boxing and unboxing, basically conversions are of two kinds: widening conversions and narrowing conversions depending if the conversion is explicit or implicit. This is explained next.

Widening Conversions

Widening conversions occur when you try to convert a type into another one that can include all values of the original type. A typical example of a widening conversion is converting from an Integer into a Double, as in the following lines of code:

'Widening conversion Dim i As Integer = 1 Dim d As Double = i

As you might remember from Table 4.2, Integer represents a numeric value whereas Double represents a large floating number. Therefore, Double is greater than Integer and therefore ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.