.net – Option Strict和Option Explicit有什么作用?

我看到这个帖子:

Typos… Just use option strict and explicit please.. during one software development project,which I was on as a consultant,they were getting ridiculous amounts of errors everywhere… turned out the developer Couldn’t spell and would declare variables with incorrect spelling.. no big deal,until you use the correct spelling when you’re assigning a value to it… and you had option explicit off. Ouch to them…”

什么是选项严格和选项显式?我已经google了它,但不能得到的想法(因为大多数是Visual Basic,我做PHP)。

Option Explicit意味着必须声明所有变量。见 here.没有这个,你可以不小心声明一个新的变量,只是拼错另一个变量名。这是其中的一个事情,导致很多的悲伤,因为你试图调试VB程序,找出为什么你的程序不能正常工作。在我看来,这不应该是一个选项 – 它应该永远在。

选项严格“将隐式数据类型转换限制为仅扩大转换”。请参见here.启用此选项后,您不能意外地将一种数据类型转换为不太精确的另一种数据类型(例如,从整数到字节)。同样,认情况下应打开的选项。

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...