为什么在C#中经常看到“NULL!=变量”而不是“变量!=NULL”?在C#中,对于你陈述条件的顺序,过剩速度有什么不同吗?if (null != variable) ...if (variable != null) ...自从最近,我经常看到第一个,它引起了我的注意,因为我已经习惯了第二个。如果没有区别,第一个有什么好处呢?
3 回答
慕桂英4014372
TA贡献1871条经验 获得超13个赞
// Probably wrongif (x = 5)
if (x == 5)
if (5 == x)
x=5Int32Boolean.
千万里不及你
TA贡献1784条经验 获得超9个赞
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
}}
慕勒3428872
TA贡献1848条经验 获得超6个赞
int i = 0;if (i = 1){
...}- 3 回答
- 0 关注
- 479 浏览
添加回答
举报
0/150
提交
取消
