I am trying to create a line extension method with the following signature:
public static DateTime? TryParseExact(this string src, string format, IFormatProvider provider = DateTimeFormatInfo.CurrentInfo, DateTimeStyles style = DateTimeStyles.None)
{
}
I get a compiler error:
The default parameter value for 'provider' must be a compile-time constant
Could not find anything on Google, and my only job is:
public static DateTime? TryParseExact(this string src, string format, IFormatProvider provider = null, DateTimeStyles style = DateTimeStyles.None)
{
if (provider == null)
provider = DateTimeFormatInfo.CurrentInfo;
}
Does anyone know how I can set the default for IFormatProvider in a signature? Is it possible? IFormatProvider is an interface, so I guess where the problem is.
source
share