为什么 is 关键字需要非空表达式?
is 关键字的 MSDN 文档说:
expression is not null
为什么? 如果 MethodThatReturnsNull() 类型 被调用,那么不应该返回 false,因为 null 肯定不是该类型?
The MSDN documentation for the is keyword says:
expression is not null
Why? If MethodThatReturnsNull() is type were called shouldn't that return false since null certainly isn't that type?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果
表达式
为null
,它会返回false
。 也许您误解了文档?It does return
false
ifexpression
isnull
. Perhaps you're misunderstanding the documentation?关于 null ,您唯一可以肯定的是您不知道它是什么。 与 null 进行比较的结果通常为 null ...
问: 1 == “我不知道”吗?
答:“我不知道”
查看 这篇博文,作者:Eric Lippert。
The only thing you can say for certain about null is that you don't know what it is. Comparing something to null generally has a result of null ...
Q: Does 1 == "I don't know"?
A: "I dont know"
Check out this blog post by Eric Lippert.
您无法静态解析 null。
You can't statically resolve a null.
这是我对类似问题给出的一个非常受欢迎的答案。
C# 获取 null 对象的类型
This was a pretty popular answer I gave to a similar question.
C# get type of null object