Option Strict 和 Option Explicit 有什么作用? [英] What do Option Strict and Option Explicit do?

查看:45
本文介绍了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…"

Option StrictOption Explicit 到底是什么?我已经用谷歌搜索了它,但无法理解(因为主要是 Visual Basic,我在做 PHP).

What is Option Strict and Option Explicit anyway? I have googled it up but can't get the idea (because mostly it's Visual Basic, I'm doing PHP).

推荐答案

Option Explicit 意味着必须声明所有变量.请参阅此处.如果没有这个,你可能会因为拼错另一个变量名而意外地声明一个新变量.当您尝试调试 VB 程序并找出您的程序无法正常运行的原因时,这是导致很多痛苦的事情之一.在我看来,这甚至不应该是一种选择 - 它应该始终开启.

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将隐式数据类型转换限制为仅扩展转换".请参阅此处.启用此选项后,您不会意外地将一种数据类型转换为另一种不太精确的数据类型(例如,从 IntegerByte).同样,默认情况下应该打开的选项.

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.

这篇关于Option Strict 和 Option Explicit 有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆