c# - handling null values of datetime -


i have linq query , consists of datetime field i'm extracting database

           terminationdate = base.convertfromutctocentral(r.terminationdate.tostring()) 

the function used designed this

           public datetime convertfromutctocentral(string utctime)     {          if (utctime != "")         {             datetime?  retvalue = timezoneinfo.converttimefromutc(convert.todatetime                                                        (utctime), ustimezones.central);              return convert.todatetime(retvalue);         }         else             return convert.todatetime(null);      } 

but whenever return null shows min date in grid assign query to. however, when null, should showup null instead of min date. can please let me know how can handle this?also let me knoww if using ternary operator better idea.

restrictions: can't change function retrun type used in several places

since returning value type, datetime, can not return null. can either change function return nullible datetime (datetime?), throw exception, or return default value datetime, default(datetime). imho throw system.argumentexception since empty string convert not going produce output.


Comments