+92 332 4229 857 99ProjectIdeas@Gmail.com

Option Strict (Vb.net)


Option Strict
This statement is used to allow or restrict implicit conversions. By default Option Strict is Off.
·         Option Strict Off
·         Option Strict On

Option Strict On

By setting the Option Strict to be On, it will restrict implicit conversions. It will generate an error when user tries to convert a variable of large capacity data-type to a smaller capacity data-type.

Example

Dim intVar As Integer = 0
Dim doubleVar As Double = 12.345
intVar = doubleVar
MsgBox(intVar)

In this case the compiler will generate an error that Option Strict On disallows implicit conversion from double to integer because Option Strict is set to On.

Option Strict Off

By setting the Option Strict to be Off, it will allow implicit conversions.

Example

Dim intVar As Integer = 0
Dim doubleVar As Double = 12.345
intVar = doubleVar
MsgBox(intVar)

In this case the compiler will allow implicit conversion from double to integer and the value 12 will be displayed in the message box because Option Strict is set to Off.

0 comments: