Search code examples
c#datetimedefault

new DateTime() vs default(DateTime)


Is there a reason to choose one of these over the other?

DateTime myDate = new DateTime();

or

DateTime myDate = default(DateTime);

Both of them are equal 1/1/0001 12:00:00 AM.


Solution

  • No, they are identical.

    default(), for any value type (DateTime is a value type) will always call the parameterless constructor.