What do Option Strict and Option Explicit do?

前端 未结 3 1156
天命终不由人
天命终不由人 2020-11-21 07:37

I saw this post:

Typos… Just use option strict and explicit please.. during one software development project, which I was on as a consultant, they w

3条回答
  •  粉色の甜心
    2020-11-21 08:05

    Option Explicit means that all variables must be declared. See here. Without this, you can accidentally declare a new variable just by misspelling another variable name. This is one of those things that cause a lot of grief as you're trying to debug VB programs and figure out why your program isn't working properly. In my opinion, this shouldn't even be an option - it should always be on.

    Option Strict "restricts implicit data type conversions to only widening conversions". See here. With this option enabled, you can't accidentally convert one data type to another that is less precise (e.g. from an Integer to a Byte). Again, an option that should be turned on by default.

提交回复
热议问题