可空类型是引用类型吗? [英] Are nullable types reference types?
本文介绍了可空类型是引用类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我声明一个 int
为可空时
When I declare an int
as nullable
int? i=null;
这里的 i
会变成引用类型吗?
Does i
here become a reference type?
推荐答案
不,可空对象是结构体.发生的事情是可空结构有两个值:
No, a nullable is a struct. What is happening is that the nullable struct has two values:
- 数据类型的值(
int
表示int?
,DateTime
表示DateTime?
等.). - 一个布尔值,表示是否已设置数据类型值.(
HasValue
是属性.)
- The value of the data type (
int
forint?
,DateTime
forDateTime?
, etc.). - A boolean value which tells if the data type value has been set. (
HasValue
is the property.)
当您设置数据类型的值时,结构将 HasValue
更改为 true.
When you set the value of the data type, the struct changes HasValue
to true.
这篇关于可空类型是引用类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文