它是什麼
允許在宣告變數時使用本地型別推斷。
什麼是型別推斷?
你可以在不明確宣告資料型別的情況下宣告區域性變數。編譯器根據其初始化表示式的型別推斷變數的資料型別。
選項推斷 :
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