c# - Differences Nullable values: .Value or not? -


i'm kinda new nullable. have datetime in c# want null, assign value in try-catch, , after check whether it's null or not.

code:

datetime? dt = null; try {     dt = datetime.parseexact(stringdate, "yyyy-mm-dd hh:mm:ss", cultureinfo.invariantculture); } catch(formatexception) {     console.writeline("the given string not valid , not converter datetime"); } // check if datetime not null // if it's not null, datetime 

so, question:

which of 2 should use, why should use it, , differences between both:

if(dt != null) {     dosomethingwithdatetime(dt); } 

or:

if(dt.hasvalue) {     dosomethingwithdatetime(dt.value); } 


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -