0

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?

Ricardo Peres
  • 13,724
  • 5
  • 57
  • 74
Ackdari
  • 3,222
  • 1
  • 16
  • 33

0 Answers0