AndAlso / OrElse用法 [英] AndAlso/OrElse usage

查看:118
本文介绍了AndAlso / OrElse用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下使用AndAlso和OrElse是否更好,而不是使用版本和

&或者?


MikeH

Is it better to use AndAlso and OrElse by default rather than the regual And
& Or?

MikeH

推荐答案

嗨迈克,


您的消息中存在语法错误
Hi Mike,

There is a syntax error in your message
默认情况下使用AndAlso和OrElse是否更好,而不是使用regual
和&或者?
Is it better to use AndAlso and OrElse by default rather than the regual And & Or?




它必须是

使用AndAlso AndAlso OrElse默认情况下更好,而不是使用版本

And AndAlso Or?


这不严重,但你有我的答案,


Cor



It has to be
Is it better to use AndAlso AndAlso OrElse by default rather than the regual
And AndAlso Or?

This was not serious, but you have my answer,

Cor


*" Mike Hale" < MH *** @ jcaho.org> scripsit:
* "Mike Hale" <mh***@jcaho.org> scripsit:
默认情况下使用AndAlso和OrElse是否更好,而不是使用版本和
&或者?
Is it better to use AndAlso and OrElse by default rather than the regual And
& Or?




您是否阅读过文档?这取决于具体情况...


-

Herfried K. Wagner

MVP·VB Classic,VB.NET

< http://www.mvps.org/dotnet>


< http://www.plig.net/nnq/nquote。 html>



Did you read the documentation? It depends on the case...

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>


效果不同。


我专门使用AndAlso / OrElse,因为它会使评估短路
其余的



和/或评估整个陈述,无论其中的一部分是否为
false或True。非常低效。


AndAlso / OrElse从左到右进行评估,直到满足条件。

我认为MS本来希望用AndAlso替换和/或/ OrElse,但

它会在升级过程中破坏许多VB应用程序。如果一个

的程序员做了类似的事情:


如果x和y()那么....


和y()做了一些处理,改变了应用程序的状态...

破解了应用程序。

C#以及我能想到的其他语言评估像还要

OrElse。


另一个考虑因素是你需要先测试Null(Nothing)的价值

然后测试该值的一部分。并且会导致运行时错误:


如果不是x什么也没有,x.myprop ...

异常将被抛出如果x为空,因为它评估在右边。


如果不是x什么都没有,还有x.myprop ....

如果x什么也没有,
将不会抛出异常。


-


Justin Weinberg

设计PrintDocument?绘制到表格?

www.mrgsoft.com

" Mike Hale" < MH *** @ jcaho.org>在消息中写道

新闻:ez ************** @ TK2MSFTNGP11.phx.gbl ...
The effects are different.

I exclusively use AndAlso / OrElse because it short circuits the evaluation
of the rest.

And / Or evaluates the entire statement, regardless if a part of it was
false or True. Very inefficient.

AndAlso / OrElse evaluates from left to right until the condition is met.
I think MS would have liked to replace And / Or with AndAlso / OrElse, but
it would have broken many VB applications in the upgrade process. If a
programmer had done something like:

If x and y() then....

and y() did some processing which changed the state of the application...
broken app.
C# and the rest of the languages I can think of evaluate like AndAlso
OrElse.

One other consideration is if you needed to test a value for Null (Nothing)
first and then test a part of that value. And would cause a runtime error:

If not x is nothing and x.myprop...
exception will be thrown if x is nothing because it evaluates to the right.

If not x is nothing andalso x.myprop....

exception will not be thrown if x is nothing.

--

Justin Weinberg
Designing a PrintDocument? Drawing to forms?
Check out GDI+ Architect at www.mrgsoft.com
"Mike Hale" <mh***@jcaho.org> wrote in message
news:ez**************@TK2MSFTNGP11.phx.gbl...
使用起来更好AndAlso和OrElse默认情况下而不是regual
And&或者?

MikeH
Is it better to use AndAlso and OrElse by default rather than the regual And & Or?

MikeH



这篇关于AndAlso / OrElse用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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