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

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

内容简介:因为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有实例属性吗?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

Writing Windows VxDs and Device Drivers, Second Edition

Writing Windows VxDs and Device Drivers, Second Edition

Karen Hazzah / CMP / 1996-01-12 / USD 54.95

Software developer and author Karen Hazzah expands her original treatise on device drivers in the second edition of "Writing Windows VxDs and Device Drivers." The book and companion disk include the a......一起来看看 《Writing Windows VxDs and Device Drivers, Second Edition》 这本书的介绍吧!

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

html转js在线工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具