Nullable<T>
is a struct that has the following definition:
public struct Nullable<T> where T : struct
where struct
is a type constraint so that T is constrained to (according to the spec §4.4.4):
- struct type or enum type
- not a nullable type.
Looking in the source for Nullable<T>
there are no special attributes (expect for [Serializable]
), so how does the compiler can recognise it as a "nullable type"?
In response to the comments below:
int
is an alias for Int32
:
(§4.1.4) simple types are identified through reserved words, but these reserved words are simply aliases for predefined struct types in the System namespace
T?
is shorthand for Nullable<T>
:
(§4.1.10) - A nullable type is written T?, where T is the underlying type. This syntax is shorthand for System.Nullable, and the two forms can be used interchangeably.
This seems to be a distinct difference which isn't reflected below.
So how does the compiler recognise a simple struct (with no special code) as a "nullable type", struct name?