Default parameter for value must be a compile time constant?

DateTime.MinValue is not a const, because the language doesn’t like const on DateTime. One option is to use DateTime? instead, i.e.

public static void DatesToPeriodConverter(DateTime start, DateTime? end = null,
     out string date, out string time)
{
    var effectiveEnd = end ?? DateTime.MinValue;
    // ...
}

However, you will still have the issue of having non-default parameters after default parameters – you may need to re-order them to use that as a default.

Leave a Comment