VB.Net - Option Strict

This is switched off by default but actually appears as "(custom)"
The default is off which is to allow implicit type casting (or late binding).
When switched on it will prevent narrowing conversions without explicit casting.


Right click on your project and select "Properties"
Display the Compile tab
SS


This setting does not exist in C#, because implicit data type converson is not allowed.
This is a new setting in VB.NET and is switched off by default.
Ensures you do not perform any unsafe type conversions
With Option Strict On you cannot perform any narrowing conversions
(i.e. you cannot cast a variable from Long to Integer without explicitly using a conversion function)
Widening is always allowed.



Special reference should be made to the function CType()
This function allows us to temporarily convert a variable of one Reference type (usually object) into another Reference type.
When Option Strict is on this is the only way to convert a variable of type Object into a more specific data type.


All objects are early bound by default
Early binding means our code is checked at compile time (before run-time errors can occur) to determine whether a certain object has the correct properties and methods.
Intellisense is a direct consequence of early binding.


If Option Strict is On, when you pass in a Single with a decimal part (eg 3.45) you must append the letter F (3.45F) to indicate to the compiler that the value is a Single and not a Double.



© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext