datetime - C# Casting vs. Parse -


this may seem rudimentary some, question has been nagging @ me , write code, figured ask.

which of following better code in c# , why?

((datetime)g[0]["myuntypeddatefield"]).toshortdatestring() 

or

datetime.parse(g[0]["myuntypeddatefield"].tostring()).toshortdatestring() 

ultimately, better cast or parse? all!

if g[0]["myuntypeddatefield"] datetime object, cast better choice. if it's not datetime, have no choice use parse (you invalidcastexception if tried use cast)


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -