VB.NET Option Strict [On | Off]

Option Strict is prevents program from automatic variable conversions, that is implicit data type conversions .

By default Option Strict is Off .

From the following example you can understand the use of Option Strict.

VB.NET Source Code

The above program is a normal program and is in default Option Strict Off . Because its Option Strict Off we can convert the value of Long to an Integer.

Take a look at the following program.

Option Strict On
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

        Dim longNum As Long
        Dim intNum As Integer

        longNum = 12345
        intNum = longNum

    End Sub
End Class

When you write this source code the compiler will shows the message.

The compiler generate error because in the program we put "Option Strict On" and prevent the program from automatic conversion. (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About