Explicit Data Conversion

What happens if you need to convert a Double to an Integer, and you know that the magnitude of the Double value is within the range of acceptable values for the Integer data type? If the implicit conversions would be the only mechanism available, you would be stuck. But they are not. An explicit conversion is a transformation function that takes a data type and transforms it into another data type. There are a number of conversion functions available in the Visual Basic language, some of which are in Table 7.1.

Table 7.1. Conversion Functions in Visual Basic .NET
Name Converts To Comments and Parameter Range
CByte Byte 0 to 255 (same as for Byte data type)
CShort Short Same as for Short data type
CInt Integer Same as for ...

Get Visual Basic® .NET by Example 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.