C# convert to date - No implicit conversion between 'System.DateTime' and '<null>' -
this question has answer here:
i have following code:
var tz = timezoneinfo.findsystemtimezonebyid("central standard time"); dateanalyzed_copper = records.dateanalyzed_copper.hasvalue ? timezoneinfo.converttimetoutc(records.dateanalyzed_copper.value, tz) : null,
......
note dateanalyzed_copper nullable datetime.
i following message
type of conditional expression cannot determined because there no implicit conversion between 'system.datetime' , '<null>'
you should cast either null
nullable datetime:
dateanalyzed_copper = records.dateanalyzed_copper.hasvalue ? timezoneinfo.converttimetoutc(records.dateanalyzed_copper.value, tz) : (datetime?)null
or datetime
value returned converttimetoutc
:
dateanalyzed_copper = records.dateanalyzed_copper.hasvalue ? (datetime?)timezoneinfo.converttimetoutc(records.dateanalyzed_copper.value, tz) : null
ternary operator needs either same types on both branches, or there should implicit conversion between them. have different types, , there no implicit converstion between datetime
, null
. so, shoul use explicit one.
Comments
Post a Comment