Saturday, February 23, 2008

Option Strict Statement

1. If turn the option strict off, it allows implicit type conversion

2. If turn on, the compiler will alert your the conversion is not allowed

3. Here is another example

4. if you turn if off, the conversion error will appear in run time

  • C# is a strongly typed language. VB.NET, on the other hand, is not by default, unless you turn on the Option Strict option.
  • Option Strict On prevents implicit type conversions by the compiler.
  • Set Option Strict to On to improve type checking of your VB.NET code. On rare occasions, you may find setting Option Strict Off to be of benefit, especially when you need to interoperate with late-binding COM Components exposing only the IDispatch interface. In these cases, set Option Strict Off only in those isolated files (classes) that interact with the components.

.NET Gotchas

blog comments powered by Disqus