Export (0) Print
Expand All

Type Checking

When converting between data types, the Visual Basic compiler can operate under strict or permissive type semantics. If strict type semantics are in effect, only widening conversions are permitted implicitly, and narrowing conversions must be explicit. Under permissive type semantics, all widening and narrowing conversions can be done implicitly. Type semantics apply to conversions between all data types, including object types.

Visual Basic .NET provides a switch that controls type checking. By default, this switch is on, and the compiler enforces strict type semantics. If you turn the switch off, you can perform narrowing conversions without using conversion keywords.

You can set the type checking switch on or off in any of the following ways:

  • Setting the appropriate project property in the Properties window of the integrated development environment (IDE)
  • Specifying the /optionstrict command-line compiler option
  • Including the Option Strict statement at the beginning your code

If you use the Option Strict statement, that setting overrides both the project property and compiler option settings, but only for the source code file in which it appears.

Setting Option Strict On has the advantage of forcing early binding. This improves performance.

See Also

Widening and Narrowing Conversions | Implicit and Explicit Conversions | Option Strict Statement | /optionstrict | Setting Visual Basic Project Properties

Show:
© 2014 Microsoft