开发者

Nullable<> types are a BCL, CLR, or both implementation?

开发者 https://www.devze.com 2023-02-05 05:24 出处:网络
Some time ago I thought that Nullable<> value types are classes, encapsulating value types and a bool to HasValue. With som开发者_开发技巧e implicit cast operador for null, just implemented at BCL.

Some time ago I thought that Nullable<> value types are classes, encapsulating value types and a bool to HasValue. With som开发者_开发技巧e implicit cast operador for null, just implemented at BCL.

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


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


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.


Nullable<> is a struct implemented within mscorlib.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消