Nullable type and if issue

前端 未结 4 1255
暖寄归人
暖寄归人 2020-12-21 05:08

Here is simplest piece of code

Dim testInvoiceDate As DateTime? = If(String.IsNullOrEmpty(Nothing),
                                      Nothing,
                   


        
4条回答
  •  無奈伤痛
    2020-12-21 05:48

    Nothing in VB.Net is the equivalent of default(T) in C#: the default value for the given type.

    • For value types, this is essentially the equivalent of 'zero': 0 for Integer, False for Boolean, DateTime.MinValue for DateTime, ...
    • For reference types, it is the null value (a reference that refers to, well, nothing).

    Asigning Nothing to a DateTime therefore is the same as assigning it DateTime.MinValue

提交回复
热议问题