VB.NET les valeurs null DateTime et Opérateur Ternaire

Je vais avoir des problèmes avec un Nullable DateTime dans VB.NET (VS 2010).

Méthode 1

If String.IsNullOrEmpty(LastCalibrationDateTextBox.Text) Then
    gauge.LastCalibrationDate = Nothing
Else
    gauge.LastCalibrationDate = DateTime.Parse(LastCalibrationDateTextBox.Text)
End If

Méthode 2

gauge.LastCalibrationDate = If(String.IsNullOrEmpty(LastCalibrationDateTextBox.Text), Nothing, DateTime.Parse(LastCalibrationDateTextBox.Text))

Quand ils reçoivent une chaîne vide, la Méthode 1 assigne une valeur Null (Nothing) sur la valeur de la jauge.LastCalibrationDate mais la Méthode 2 affecte le type DateTime.MinValue.

Dans d'autres endroits dans mon code j'ai:

LastCalibrationDate = If(IsDBNull(dr("LastCalibrationDate")), Nothing, dr("LastCalibrationDate"))

Correctement ceci affecte la valeur Null (Nothing) à partir d'un Opérateur Ternaire à Nullable DateTime.

Ce qui me manque? Merci!

OriginalL'auteur anonymous | 2010-11-15