<分区>
这个问题更多的是关于向值类型添加 ?
而不是 int?
在 C# 中,int
是一种值类型。
int?
是值类型还是引用类型?
在我看来它应该是一个引用类型,因为它可以是null
。
<分区>
这个问题更多的是关于向值类型添加 ?
而不是 int?
在 C# 中,int
是一种值类型。
int?
是值类型还是引用类型?
在我看来它应该是一个引用类型,因为它可以是null
。
最佳答案
int?
相当于 Nullable<int>
这意味着它是 struct .
所以这意味着它是一个 value type .
In my opinion it should be a reference type as it can be null.
你的假设是错误的。来自文档;
Nullable structure represents a value type that can be assigned null. The Nullable structure supports using only a value type as a nullable type because reference types are nullable by design.
所以它有2个值;
Nullable<T>.HasValue
)关于c# - 是整数吗?值类型还是引用类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18743979/