I have a method that is used to format some value with a given format string and an IFormatProvider
. The signature is:
public static string FormatParameter(object parameterValue, string format, IFormatProvider formatProvider)
I want that the formatProvider is by default the CultureInfo.InvariantCulture
, but
public static string FormatParameter(object parameterValue, string format, IFormatProvider formatProvider = CultureInfo.InvariantCulture)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
produces a compile error:
CS1736 | Default parameter value for 'formatProvider' must be a compile-time constant
Is there a way to use CultureInfo.InvariantCulture
or someother standard IFormatProvider
as an default parameter value? Or do I just have to check at runtime that formatProvider
is null
and then use CultureInfo.InvariantCulture
?