它是什么
允许在声明变量时使用本地类型推断。
什么是类型推断?
你可以在不明确声明数据类型的情况下声明局部变量。编译器根据其初始化表达式的类型推断变量的数据类型。
选项推断 :
Dim aString = "1234" '--> Will be treated as String by the compiler
Dim aNumber = 4711 '--> Will be treated as Integer by the compiler
与显式类型声明:
'State a type explicitly
Dim aString as String = "1234"
Dim aNumber as Integer = 4711
选项推断关闭:
Option Infer Off
的编译器行为取决于此处已记录的 Option Strict
设置。
-
Option Infer Off - Option Strict Off
所有没有显式类型声明的变量都声明为Object
。Dim aString = "1234" '--> Will be treated as Object by the compiler
-
选项推断关闭 - 选项严格打开
编译器不允许你声明没有显式类型的变量。'Dim aString = "1234" '--> Will not compile due to missing type in declaration