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

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

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -