如何检查等号? (0 == i)或(ⅰ== 0) [英] How to check for equals? (0 == i) or (i == 0)
问题描述
好吧,我们知道,下面的两行是等价的 -
Okay, we know that the following two lines are equivalent -
-
(0 == I)
-
(我== 0)
(0 == i)
(i == 0)
另外,第一种方法是在过去的鼓舞,因为这将允许编译器给出错误信息,如果你不小心使用'='而不是'=='。
Also, the first method was encouraged in the past because that would have allowed the compiler to give an error message if you accidentally used '=' instead of '=='.
我的问题是 - 在今天的一代pretty光滑IDE的和智能的编译器,你还推荐第一种方法?
My question is - in today's generation of pretty slick IDE's and intelligent compilers, do you still recommend the first method?
在特定的,这个问题突然出现在我的脑海里,当我看到下面的code -
In particular, this question popped into my mind when I saw the following code -
if(DialogResult.OK == MessageBox.Show("Message")) ...
在我看来,我决不会建议以上。任何二次意见?
In my opinion, I would never recommend the above. Any second opinions?
推荐答案
我preFER第二个,(我== 0),因为它在读取时感觉更自然。你问人,你是21岁?,而不是,是大于或等于你的年龄21少了呢?
I prefer the second one, (i == 0), because it feel much more natural when reading it. You ask people, "Are you 21 or older?", not, "Is 21 less than or equal to your age?"
这篇关于如何检查等号? (0 == i)或(ⅰ== 0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!