为什么在C#中经常看到“NULL!=变量”而不是“变量!=NULL”?在C#中,对于你陈述条件的顺序,过剩速度有什么不同吗?if (null != variable) ...if (variable != null) ...自从最近,我经常看到第一个,它引起了我的注意,因为我已经习惯了第二个。如果没有区别,第一个有什么好处呢?
3 回答
UYOU
TA贡献1878条经验 获得超4个赞
// Probably wrongif (x = 5)
if (x == 5)
if (5 == x)
x=5Int32Boolean.
阿晨1998
TA贡献2037条经验 获得超6个赞
if(null == myDuck)
class Duck==if(myDuck == null)
null
public class myDuck{
public int quacks;
static override bool operator ==(myDuck a, myDuck b)
{
// these will overflow the stack - because the a==null reenters this function from the top again
if (a == null && b == null)
return true;
if (a == null || b == null)
return false;
// these wont loop
if (null == a && null == b)
return true;
if (null == a || null == b)
return false;
return a.quacks == b.quacks; // this goes to the integer comparison
}}
MMTTMM
TA贡献1869条经验 获得超4个赞
int i = 0;if (i = 1){
...}- 3 回答
- 0 关注
- 1404 浏览
添加回答
举报
0/150
提交
取消
