Nullable<> types are a BCL, CLR, or both implem

2019-06-26 11:08发布

Some time ago I thought that Nullable<> value types are classes, encapsulating value types and a bool to HasValue. With some implicit cast operador for null, just implemented at BCL.

But being a struct, how this can be achieved? Nullable<> struct is "special" for CLR?

3条回答
再贱就再见
2楼-- · 2019-06-26 11:29

Nullable<T> is defined as a normal struct, but there's special hooks within the CLR to box/unbox an instance of [mscorlib]System.Nullable`1 to null according to the HasValue property. There's more details on this here

查看更多
贼婆χ
3楼-- · 2019-06-26 11:32

Nullable<> is a struct implemented within mscorlib.

One special thing is in the C# compiler that recognizes X? as an alias for Nullable<X>.

查看更多
Lonely孤独者°
4楼-- · 2019-06-26 11:43

Here's the MSDN article on Nullable Types.

http://msdn.microsoft.com/en-us/library/1t3y8s4s(v=VS.100).aspx

I'm not sure what you're trying to get at with Nullable<>, unless you're mis-understanding that Nullable types are instances of the System.Nullable<T> struct.

查看更多
登录 后发表回答