(a!= b)等于!(a == b)? [英] (a != b) equivelant to !(a == b)?

查看:112
本文介绍了(a!= b)等于!(a == b)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解是类必须实现/覆盖这些运算符作为

a对,所以我希望可以安全地期望这两个运算符返回相同的

结果。是否有任何差异,表现或其他?


if(!(a == b))

{

blah blah等等。
}


if(a!= b)

{

blah blah blah < br $>
}


我正在审查一些代码而且作者只使用前者,但

2nd似乎稍微直截了当对我来说。我只是想确定它

真的只是个人意见。

My understanding is that classes must implement/override these operators as
a pair, so I would expect it''s safe to expect these two to return the same
results. Is there any difference, performance or otherwise?

if (! (a == b))
{
blah blah blah
}

if (a !=b)
{
blah blah blah
}

I''m reviewing some code and the author uses the former exclusively, but the
2nd seems slightly more straightforward to me. I just want to be sure it
really is just personal opinion.

推荐答案

* Daniel Billingsley * tippselte am * 21.10 .2003 22:19 * MESZ:


[...]


它们是等价的,我投票给第二个更容易阅读。


祝你好运,


Michael


-

Michael Kremser
http://great.dynu.com/

*Daniel Billingsley* tippselte am *21.10.2003 22:19* MESZ:

[...]

They are equivalent and I vote for the second to be easier to read.

Best regards,

Michael

--
Michael Kremser
http://great.dynu.com/


Daniel Billingsley< db ********** @ NO.durcon.SPAAMM.com>写道:
Daniel Billingsley <db**********@NO.durcon.SPAAMM.com> wrote:
我的理解是类必须实现/覆盖这些操作符作为一对,所以我希望可以安全地期望这两个返回相同的
结果。是否有任何差异,表现或其他?

如果(!(a == b))
{
等等等等等等}

if(a!= b)
{bla / blah blah
}

我正在审查一些代码而作者只使用前者,但是对我来说,第二个似乎更直接。我只是想确定它
真的只是个人意见。
My understanding is that classes must implement/override these operators as
a pair, so I would expect it''s safe to expect these two to return the same
results. Is there any difference, performance or otherwise?

if (! (a == b))
{
blah blah blah
}

if (a !=b)
{
blah blah blah
}

I''m reviewing some code and the author uses the former exclusively, but the
2nd seems slightly more straightforward to me. I just want to be sure it
really is just personal opinion.




是的 - 如果任何课程都不遵守上述规定,那么他们''重新询问*至

非常失败。


-

Jon Skeet - < sk *** @ pobox。 com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件



Yes - if any classes don''t obey the above, then they''re *asking* to
fail horribly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


是的 - 完全一样。


总是很有意思看到IL会发出什么。


在这两种情况下,如果值相等,Opcode beq.s用于跳转到目标标签(跳过匹配条件的代码块),所以如果它们不是,它将继续匹配的代码块(a!= b)。


希望以某种方式有意义。


干杯,

Wim Hollebrandse
HTTP://瓦特ww.wimdows.net
http://www.wimdows.com


---

发表于使用Wimdows.net新闻组 - http://www.wimdows.net/newsgroups/
Yep - exactly the same.

Always interesting to see what gets emitted to IL.

In both cases, the Opcode beq.s is being used to jump to the target label if the values are equal (skipping the codeblock that matches the condition), so if they''re not, it would continue with that code block that matches (a!=b).

Hope that makes sense somehow.

Cheers,
Wim Hollebrandse
http://www.wimdows.net
http://www.wimdows.com

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/


这篇关于(a!= b)等于!(a == b)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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