C# HasValue vs !=null

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17783929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 10:27:46  来源:igfitidea点击:

C# HasValue vs !=null

c#null

提问by oimitro

My question might sound a little foolish but it bugs me every time i face it. What is the difference between :

我的问题可能听起来有点愚蠢,但每次我面对它时都会让我烦恼。有什么区别:

where value.HasValue

and

where value != null

Does HasValue checks if valueis null?

HasValue 是否检查是否value为空?

采纳答案by Derek

They both do the same thing, just pick one and stick with it so that you have consistency. There is nothing to gain by using either in the end.

他们都做同样的事情,只需选择一个并坚持下去,就可以保持一致性。最终使用两者都没有任何好处。