This topic has not yet been rated - Rate this topic

Type Checking in Visual Basic

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, you can attempt all widening and narrowing conversions implicitly. Type semantics apply to conversions between all data types, including object types.

Visual Basic provides a switch that controls type checking. By default, this switch is Off, and the compiler allows implicit narrowing conversions. If you turn the switch On, the compiler enforces strict type semantics.

Type Checking Switch

You can set the type checking switch On or Off in any of the following ways:

  • Set the appropriate project property in the Properties window of the integrated development environment (IDE)

  • Specify the /optionstrict command-line compiler option

  • Include the Option Strict statement at the beginning of 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. For more information, see Option Strict Statement.

Performance Advantage

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

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.