Option Strict
Visual Basic generally allows implicit conversions of any data type to any other data type. Data loss can occur when the value of one data type is converted to a data type with less precision or smaller capacity, however, a runtime error message will occur if data will be lost in such a conversion. Option Strict ensures compile-time notification of these types of conversions so they may be avoided.
In addition to the conditions described above, Option Strict generates an error for:
The following is a list of widening conversions:
Type | Widens to |
---|---|
Boolean |
Object |
Byte |
Short, Integer, Long, Decimal, Single, Double, Object |
Char |
Integer, Long, Decimal, Single, Double, Object |
Short |
Integer, Long, Decimal, Single, Double, Object |
Integer |
Long, Decimal, Single, Double, Object |
Long |
, Decimal, Double, Object |
Single |
Double, Object |
Double |
Object |
Date |
, Object |
String |
Object |
Null |
Object |
Nothing |
Object |
Empty |
Object |
Fixed-length String |
String, Object |
class |
Object; any of the classes that it inherits from; any of the interfaces that it implements (for COM2 defined classes this will only include the interfaces listed in the class’s definition within it’s type library). |
Interface |
Object; any of the interfaces that it inherits from. |
Structure |
Object |
Array |
Object |