Prefers new DateTime .
In favor of new , this will allow you to use variables directly:
// clean because the variable is applied directly to the function int year = 2000; var date1 = new DateTime(year, 1, 15); var date1 = new DateTime(year, 7, 3); var date1 = new DateTime(year, 8, 19); // kind of gross and prone to errors because it is appended to the string int day = 23; var date1 = DateTime.Parse("2001, 5, " + day.ToString());
In the argument against Parse it does not detect errors until runtime:
var date1 = new DateTime(200fdsa, 1, 15);
DateTime.Parse will always have lower performance because it needs to run code that detects errors and converts the string to numeric values. He does this while your program is running.
However, in cases where you must accept string input (for example, from a text file), you must use the tool created for the job: DateTime.Parse .
If you are interested in simplifying the specification of date / time constants in your code, there is a library that John Skeet wrote for this.
It is a bit old and not supported, but the specific code (extension methods for integer constants / date and time structures) probably does not need a lot of maintenance.
The source code for these extensions is under MiscUtil\MiscUtil\Extensions\TimeRelated\ (inside the source zip)
This will allow you to write your dates in a more friendly manner, but you will get clean code with similar performance until new DateTime(2012, 11, 13) :
DateTime someDateAndTime = 19.June(1976) + 8.Hours();