I’m curious as to why the following code works (run under the VS debugger):
int? x = null;
null
x.HasValue
false
If x is indeed null, what instance does HasValue refer to? Is HasValue implemented as an extension method, or does the compiler special case this to make it magically work?
Because
xisn’t a reference type. The?is just syntactic sugar forNullable<T>, which is astruct(value type).