选项严格ON - 为什么使用它??? [英] Option Strict ON - WHY use it???

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

问题描述

我有一个使用Option Strict OFF创建的项目。效果很好,

不是问题。但如果我打开Option Strict,那么我会收到很多

错误。


我的问题,我是否应该关心Option Strict?

Option Strict On有什么优势?

更好的类型声明能让我的代码运行得更快吗?


如果有人知道答案!请填写我。我有想法和信念但是

我会一劳永逸地想知道区别是什么。


提前感谢


Clyde W.

I have a project that was created all with Option Strict OFF. Works great,
not a problem with it. But if I turn Option Strict ON then I get a LOT of
errors.

My question, should I even care about Option Strict?
What advantages do I get with Option Strict On?
Does better type statement make my code run faster?

If anyone knows THE ANSWERS! please fill me in. I have ideas and belief but
I would once and for all like to know what the difference is.

Thank in advance

Clyde W.


推荐答案

你应该有很多理由所有

时间都有OPTION STRICT。


我使用它的主要原因是要注意缩小转换次数。地方

在代码中,我可能无意中执行从双倍转换为

单个或者任何浮点值到整数值。

-

Gerry O''Brien

Visual Basic.NET MVP

" Microsoft News" <的Na ** @ coxinet.net>在留言中写道

news:ur ************** @ TK2MSFTNGP10.phx.gbl ...
There are likely many reasons why you should have OPTION STRICT ON all the
time.

My main reason for using it is to watch for narrowing conversions. Places
in code where I might inadvertanly perform a conversion from a double to a
single ore perhaps any floating point value to an integer value.
--
Gerry O''Brien
Visual Basic.NET MVP
"Microsoft News" <Na**@coxinet.net> wrote in message
news:ur**************@TK2MSFTNGP10.phx.gbl...
我有一个项目是使用Option Strict OFF创建的。效果很好,
不是问题。但是,如果我将Option Strict设置为ON,则会出现很多错误。

我的问题是,我是否应该关注Option Strict?
Option Strict有什么优势?在?
更好的类型声明是否使我的代码运行得更快?

如果有人知道答案!请填写我。我有想法和信念
但是
我会一劳永逸地知道有什么区别。

提前感谢

克莱德W.
I have a project that was created all with Option Strict OFF. Works great,
not a problem with it. But if I turn Option Strict ON then I get a LOT of
errors.

My question, should I even care about Option Strict?
What advantages do I get with Option Strict On?
Does better type statement make my code run faster?

If anyone knows THE ANSWERS! please fill me in. I have ideas and belief
but
I would once and for all like to know what the difference is.

Thank in advance

Clyde W.





" Microsoft News" <的Na ** @ coxinet.net>在留言中写道

news:ur ************** @ TK2MSFTNGP10.phx.gbl ...

"Microsoft News" <Na**@coxinet.net> wrote in message
news:ur**************@TK2MSFTNGP10.phx.gbl...
我有一个项目是使用Option Strict OFF创建的。工作
很棒,不是问题。但是,如果我打开Option Strict,那么我会收到很多错误。
I have a project that was created all with Option Strict OFF. Works great, not a problem with it. But if I turn Option Strict ON then I get a LOT of
errors.




如果你注意到它打开或关闭之间有什么不同,那么你不是'$

编程非常好。


打开它并修正错误。



If you notice the different between having it ON or OFF, then you aren''t
programming very well.

Turn it on and fix the errors.


克莱德,


这取决于你,当你以一种访问方式编程时,

脚本方式,你可以使用严格的选项并让电脑在运行时为你做一些事情




这直接意味着你的程序变得更加不安全而且没有
尽可能的表现。


一个简单的样本。

当你说

dim a as object

a = 1

dim 1 as integer = a

这比选择严格,但程序现在不知道

在运行时应该进行什么转换并在那一刻解决它。


选项严格必须是

dim 1作为整数= Cint(a)''或任何其他转换,转换,解析

命令并在运行时完成。


在你说之前,我自己觉得很奇怪,这不是自动构建在
中,因为编译器在运行时知道这一点。他告诉你

你选择严格禁止你从

整数到对象进行隐式转换。


因此他我可以在设计时自己这样做,至少可以通过

给出一个默认值,只需点击一下即可选择。 (或者选择

,它总是告诉你在这种情况下设置标准转换函数

情况)。


我希望这有帮助吗?


Cor
Clyde,

It is up to you, when you are programming in an access kind of way,
scripting way, you can use option strict of and let the computer do things
for you at run time.

This means directly that your program becomes more insecure and does not
have the performance as it could be.

A simple sample.
When you say
dim a as object
a = 1
dim 1 as integer = a
Than this goes with option strict of, however the program does now not know
what conversion should be done at run time and solves it at that moment.

With option strict on it has to be
dim 1 as integer = Cint(a) ''or any other casting, conversion, parsing
command and is it done at run time.

Before you say it, I myself find it strange that this is not build in
automaticly, because the compiler knows this at run time. He tells you that
you that Option Strict Disallows you to do an implicit conversion from
integer to object.

Therefore he can do that in my opinion in design time himself at least by
giving a default which can be choosen with one click. (Or with an option
which tells always to set the standard conversion function in this kind of
situations).

I hope this helps?

Cor


这篇关于选项严格ON - 为什么使用它???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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