VB.NET - Nullable DateTime and Ternary Operator -
i'm having problems nullable datetime in vb.net (vs 2010).
method 1
if string.isnullorempty(lastcalibrationdatetextbox.text) gauge.lastcalibrationdate = nothing else gauge.lastcalibrationdate = datetime.parse(lastcalibrationdatetextbox.text) end if
method 2
gauge.lastcalibrationdate = if(string.isnullorempty(lastcalibrationdatetextbox.text), nothing, datetime.parse(lastcalibrationdatetextbox.text))
when given empty string method 1 assigns null (nothing) value gauge.lastcalibrationdate method 2 assigns datetime.minvalue.
in other places in code have:
lastcalibrationdate = if(isdbnull(dr("lastcalibrationdate")), nothing, dr("lastcalibrationdate"))
this correctly assigns null (nothing) ternary operator nullable datetime.
what missing? thanks!
i admit i'm not expert on this, apparently stems 2 things:
- the
if
ternary operator can return 1 type, in case date type, not nullable date type - the vb.net
nothing
value notnull
equivalent default value of specified type, in case date, not nullable date. hence date minimum value.
i derived of information answer post: ternary operator vb vs c#: why resolves integer , not integer?
hope helps , joel coehoorn can shed more light on subject.
Comments
Post a Comment