如何检查等号? (0 == i)或(ⅰ== 0) [英] How to check for equals? (0 == i) or (i == 0)

查看:167
本文介绍了如何检查等号? (0 == i)或(ⅰ== 0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我们知道,下面的两行是等价的 -

Okay, we know that the following two lines are equivalent -


  1. (0 == I)

  2. (我== 0)

  1. (0 == i)
  2. (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屋!

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