我在VB.NET(VS 2010)中遇到Nullable DateTime的问题。VB.NET - 可为空的DateTime和三元运算符
方法1
If String.IsNullOrEmpty(LastCalibrationDateTextBox.Text) Then
gauge.LastCalibrationDate = Nothing
Else
gauge.LastCalibrationDate = DateTime.Parse(LastCalibrationDateTextBox.Text)
End If
方法2
gauge.LastCalibrationDate = If(String.IsNullOrEmpty(LastCalibrationDateTextBox.Text), Nothing, DateTime.Parse(LastCalibrationDateTextBox.Text))
当给定一个空字符串方法1分配一个空(没有)值gauge.LastCalibrationDate但方法2为其分配DateTime.MinValue。
在我的代码中的其他地方,我有:
LastCalibrationDate = If(IsDBNull(dr("LastCalibrationDate")), Nothing, dr("LastCalibrationDate"))
这正确地从一个三元运算符指定空(没有)为可空的DateTime。
我错过了什么?谢谢!
+1不错的工作添加将产生所需结果的解决方法。 – 2010-11-16 16:02:23