c# – 为什么一个int?设置为null有实例属性吗?

栏目: C# · 发布时间: 7年前

内容简介:因为x不是引用类型.的?只是翻译自:https://stackoverflow.com/questions/8581421/why-can-an-int-set-to-null-have-instance-properties

我很好奇以下代码的工作原理(在VS调试器下运行):

int? x = null;
null
x.HasValue
false

如果x确实为null,那么HasValue引用的实例是什么? HasValue是作为扩展方法实现的,还是编译器特殊情况这使它神奇地起作用?

因为x不是引用类型.的?只是 Nullable<T> 的语法糖,这是一个结构(值类型).

翻译自:https://stackoverflow.com/questions/8581421/why-can-an-int-set-to-null-have-instance-properties


以上所述就是小编给大家介绍的《c# – 为什么一个int?设置为null有实例属性吗?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web 2.0 Architectures

Web 2.0 Architectures

Duane Nickull、Dion Hinchcliffe、James Governor / O'Reilly / 2009 / USD 34.99

The "Web 2.0" phenomena has become more pervasive than ever before. It is impacting the very fabric of our society and presents opportunities for those with knowledge. The individuals who understand t......一起来看看 《Web 2.0 Architectures》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

html转js在线工具
html转js在线工具

html转js在线工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换