c# - Why does Nullable<T> HasValue property not throw NullReferenceException on Nulls? -
consider following code:
datetime? ndate = null; console.writeline(ndate.hasvalue);
i have expected nullreferenceexception, hasvalue indeed return false. however, since ndate null, how property invocation succeed, since there no object invoke property hasvalue on?
technically, "ndate" not null - value type, it's value specified being null.
when write datetime?
, shorthand nullable<datetime>
, struct. there no way technically null, since it's not reference type.
Comments
Post a Comment