This question already has an answer here:
- VB.NET Nothing Datetime? dataReader 2 answers
I've run into the issue that my If operator returns an unexpected value and I don't understand why. Using seemingly the same piece of code with the If statement it does work as expected. An example of the code:
Dim c As Object = DBNull.Value
Dim d As Date?
If TypeOf c Is Date Then
d = DirectCast(c, Date)
Else
d = Nothing
End If
'd returns null as expected
Dim e As Date? = If(TypeOf c Is Date, DirectCast(c, Date), Nothing)
'e returns DateTime.MinValue
Aucun commentaire:
Enregistrer un commentaire