mardi 5 janvier 2016

c# ((DateTime)object) vs Datetime.Parse

I'm new to c#.

I've an SQLite table containing "marketDate" field (datatype Date) and I'm using SQLiteDataReader.

I need to build a string this way: MONDAY 2016-01-03

So far I've found 2 ways of doing it:

1)

myString = (DateTime.Parse(reader["marketDate"].ToString())).ToString("dddd").ToUpper() + " " + (DateTime.Parse(reader["marketDate"].ToString())).ToShortDateString();

2)

myString = ((DateTime)reader["marketDate"]).ToString("dddd").ToUpper() + " " + ((DateTime)reader["marketDate"]).ToShortDateString();

I'd like to know which is the best way of doing it (best practice), and I'd really appreciate if someone will explain me the differences beetween the 2 approaches datetime.parse and (datetime)object). I couldn't find any info about the second one.

Thanks

Aucun commentaire:

Enregistrer un commentaire