Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 318
Felipe Pessoto Avatar asked Feb 25 '23 09:02

Felipe Pessoto


1 Answers

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

like image 112
thecoop Avatar answered Mar 07 '23 15:03

thecoop