Enables the use of local type inference in declaring variables.
What is type inference?
You can declare local variables without explicitly stating a data type. The compiler infers the data type of a variable from the type of its initialization expression.
Option Infer On:
Dim aString = "1234" '--> Will be treated as String by the compiler Dim aNumber = 4711 '--> Will be treated as Integer by the compiler
vs. explicit type declaration:
'State a type explicitly Dim aString as String = "1234" Dim aNumber as Integer = 4711
Option Infer Off:
The compiler behavior with
Option Infer Off depends on the
Option Strict setting
which is already documented here.
Option Infer Off - Option Strict Off
All variables without explicit type declarations are declared as
Dim aString = "1234" '--> Will be treated as Object by the compiler
Option Infer Off - Option Strict On
The compiler won´t let you declare a variable without an explicit type.
'Dim aString = "1234" '--> Will not compile due to missing type in declaration