在VB.NET中,有没有一种方法可以将DateTime
变量设置为“未设置”?为什么可以将DateTime
设置为Nothing
,但无法检查它是否为Nothing
?例如:
Dim d As DateTime = Nothing
Dim boolNotSet As Boolean = d Is Nothing
第二个语句会抛出此错误:'Is' operator does not accept operands of type 'Date'. Operands must be reference or
nullable types.
= Nothing
或<> Nothing
并不是一个好的做法:“当检查引用(或可空值类型)变量是否为null时,不要使用= Nothing
或<> Nothing
。总是使用Is Nothing
或IsNot Nothing
。” - DavidRR