Why is null not allowed for DateTime in C#?

前端 未结 6 777
情书的邮戳
情书的邮戳 2021-01-01 08:42

Why it is not allowed to assign null to a DateTime in C#? How has this been implemented? And can this feature be used to make your own classes non-nullable?

Example:

6条回答
  •  佛祖请我去吃肉
    2021-01-01 09:19

    DateTime is a value type, same as an int. Only reference types (like string or MyCustomObject) can be null. Reference types really store "references" to the objects location on the heap.

    here's a article I found that explains it better. and here's the MSDN article on it

提交回复
热议问题