Optional types <> are BCL, CLR, or both?

Some time ago I thought that Nullable <> value types are classes that encapsulate value types and bool for HasValue. With some implicit cast operator for null just implemented in BCL.

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

+4
source share
3 answers

Nullable<T> is defined as a normal structure, but there are special interceptors in the CLR to [mscorlib]System.Nullable`1 / unpack the [mscorlib]System.Nullable`1 instance to null according to the HasValue property. There is more about this here

+8
source

Here's an MSDN article on Nullable Types.

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

I'm not sure what you are trying to get with Nullable <> unless you understand that Nullable types are instances of the System.Nullable<T> structure.

0
source

Nullable<> is a structure implemented in mscorlib.

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

0
source

Source: https://habr.com/ru/post/1335586/


All Articles