使用 NOT 或 <> 哪个更好?比较值时? [英] Is it better to use NOT or <> when comparing values?

查看:23
本文介绍了使用 NOT 或 <> 哪个更好?比较值时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 VBScript 中比较值时,使用 NOT 还是使用 <> 更好?
这是:

<预><代码>如果不是 value1 = value2 那么

或者这个:

<预><代码>如果值1<>value2 然后

更好?

这是我的反驳.
在寻找逻辑否定布尔值时,您将使用 NOT 运算符,因此这是正确的:

<预><代码>如果不是 boolValue1 那么

并且在第一个示例的情况下进行比较时,将返回一个布尔值.这些值要么等于 True,要么不等于 False.因此使用 NOT 运算符是合适的,因为您在逻辑上否定了布尔值.

为了便于阅读,将比较放在括号中可能会有所帮助.

解决方案

后者(<>),因为前者的含义不清楚,除非你对应用于 Not= 运算符的操作顺序:很容易被忽略的微妙之处.

Is it better to use NOT or to use <> when comparing values in VBScript?
is this:


If NOT value1 = value2 Then

or this:


If value1 <> value2 Then

better?

EDIT: Here is my counterargument.
When looking to logically negate a Boolean value you would use the NOT operator, so this is correct:


 If NOT boolValue1 Then

and when a comparison is made in the case of the first example a Boolean value is returned. either the values are equal True, or they are not False. So using the NOT operator would be appropriate, because you are logically negating a Boolean value.

For readability placing the comparison in parenthesis would probably help.

解决方案

The latter (<>), because the meaning of the former isn't clear unless you have a perfect understanding of the order of operations as it applies to the Not and = operators: a subtlety which is easy to miss.

这篇关于使用 NOT 或 &lt;&gt; 哪个更好?比较值时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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