-optionstrict
Enforces strict type semantics to restrict implicit type conversions.
Syntax
-optionstrict[+ | -]
-optionstrict[:custom]
Arguments
+
| -
Optional. The -optionstrict+
option restricts implicit type conversion. The default for this option is -optionstrict-
. The -optionstrict+
option is the same as -optionstrict
. You can use both for permissive type semantics.
custom
Required. Warn when strict language semantics are not respected.
Remarks
When -optionstrict+
is in effect, only widening type conversions can be made implicitly. Implicit narrowing type conversions, such as assigning a Decimal
type object to an integer type object, are reported as errors.
To generate warnings for implicit narrowing type conversions, use -optionstrict:custom
. Use -nowarn:numberlist
to ignore particular warnings and -warnaserror:numberlist
to treat particular warnings as errors.
To set -optionstrict in the Visual Studio IDE
Have a project selected in Solution Explorer. On the Project menu, click Properties.
Click the Compile tab.
Modify the value in the Option Strict box.
To set -optionstrict programmatically
Example
The following code compiles Test.vb
using strict type semantics.
vbc -optionstrict+ test.vb
See also
Phản hồi
https://aka.ms/ContentUserFeedback.
Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem:Gửi và xem ý kiến phản hồi dành cho