I'm trying to create a string extension method with the following signature:
public static DateTime? TryParseExact(this string src, string format, IFormatProvider provider = DateTimeFormatInfo.CurrentInfo, DateTimeStyles style = DateTimeStyles.None)
{
}
I'm getting a compiler error:
Default parameter value for 'provider' must be a compile-time constant
Couldn't find anything on google and my only work around is to do this:
public static DateTime? TryParseExact(this string src, string format, IFormatProvider provider = null, DateTimeStyles style = DateTimeStyles.None)
{
if (provider == null)
provider = DateTimeFormatInfo.CurrentInfo;
}
Anyone know how I can set the default value of IFormatProvider in the signature? Is it even possible? IFormatProvider is an interface so I'm assuming that's where the issue lies.