C# convert to date - No implicit conversion between 'System.DateTime' and '<null>' -


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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -