null!= object和object之间有什么区别!= null [英] what is the difference between null != object and object!=null

查看:396
本文介绍了null!= object和object之间有什么区别!= null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

哪种方式更好“ null!= object”或ldquo; object!= null”?

为什么人们常常看到null!= variable”代替“变量!= null”在C#中?

‘ … != null’或者‘ null!=…’最佳表现?

请指导我。
null!= object和object之间的区别是什么!= null

对于.equal(something)和something相同.equals()

Please guide me. what is the difference between null != object and object!=null
same for "".equal("something") and "something".equals("")

哪一个有利于处理。

推荐答案

前两个是等价的,但是null!= object是一种古老的做法,它可以编写if(object = null)并且意外地将null赋给对象。这是一个阻止这次事故发生的警卫。

The first two are equivalent, but the "null != object" is an old practice from languages where it is valid to write "if (object = null)" and accidentally assign null to the object. It is a guard to stop this accident from happening.

第二个虽然等价有额外的好处,如果something为null你将不会获得空引用异常,而如果你这样做的话:.equals()。

The second whilst equivalent has the added advantage that if "something" is null you will not get a null reference exception whereas you would if you did: something".equals("").

这篇关于null!= object和object之间有什么区别!= null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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