做什么选项严格和显式的选项呢? [英] What do Option Strict and Option Explicit do?

查看:165
本文介绍了做什么选项严格和显式的选项呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到这个帖子:

错别字......只要使用选项严格和明确的请..在一个软件开发项目,这是我作为一个顾问,他们到处都拿到错误的荒谬的数额......原来,开发商不会拼,并将与声明变量不正确的拼写..没什么大不了的,直到你使用正确的拼写,当你赋值给它......你有明确的选项关闭。哎哟他们......

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)。

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).

推荐答案

所有的变量都必须声明选项显式的手段。请参见这里。如果没有这一点,你可以不小心只是拼写错误另一个变量的名称声明一个新的变量。这是那些东西,导致很多痛苦,你正在试图调试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.

选项严格限制隐式数据类型转换,只扩大转换。请参见这里。通过启用该选项,你可以不小心一种数据类型转换为另一种是不太precise(例如:从整数到字节)。同样,这应该是默认打开的选项。

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.

这篇关于做什么选项严格和显式的选项呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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