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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -