DateTime.MinValue
(и DateTime.MaxValue
) являются public static readonly
членами, а не константами времени компиляции.
Вместо использования DateTime.MinValue
в качестве значения по умолчанию, почему бы не использовать обнуляемый DateTime (DateTime?
)).Это делает ваше намерение более ясным, чем использование по умолчанию минимально возможного значения datetime.
Примерно так:
private void test(string something, DateTime? testVar = null )
{
if ( testVar.HasValue )
{
DoSomethingUsefulWithTimestamp( something , testVar.Value ) ;
}
else
{
DoSomethingElseWithoutTimestamp( something ) ;
}
return ;
}
private void DoSomethingUsefulWithTimestamp( string something , DateTime dt )
{
... // something useful
}
private void DoSomethingElseWithoutTimestamp( string something )
{
... // something useful
}
В качестве альтернативы установите значение по умолчанию в теле метода:
private void test(string something, DateTime? testVar = null )
{
DateTime dtParameter = testVar ?? DateTime.MinValue ;
DoSomethingUsefulWithTimestamp( something , dtParameter ) ;
}