この単純なコードから得られる独特の結果を次に示します。
文字列として宣言せずに、文字列型の変数を作成したいとします。これを行うと、コンパイラからエラーが発生しなくなります。
Option Strict On
' Produces no errors:
Dim MyString = "Random String"
これを行うこともできますが、エラーは発生しません。
Option Infer Off
' Produce no errors as well.
Dim MyString = "Random String"
ただし、 Option String OnとOption Infer Offの両方を組み合わせると、エラーが発生します。
Option Strict On
Option Infer Off
' The following line generates an error -
' Option Strict On requires all variable declarations to have an "As" clause
Dim MyString = "Random String"
Option StrictをOption Inferと組み合わせる必要があるのはなぜですか? 特に、次のエラーが「Option Strict」タイプであることをエラーが具体的に示している場合。Option Strictだけでは、その行をエラーとして検出できないのはなぜですか?