For a given .NET assembly compiled from C# (latest version), I would like to force all the string interpolations to systematically use CultureInfo.InvariantCulture
instead of using CultureInfo.CurrentCulture
. Is there any way to enforce this?
Asked
Active
Viewed 1,054 times
6

Joannes Vermorel
- 8,976
- 12
- 64
- 104
-
1You can specify if string interpolation should use the invariant culture by using https://learn.microsoft.com/en-us/dotnet/api/system.formattablestring.invariant – ckuri Aug 31 '20 at 16:32
-
https://stackoverflow.com/questions/2329297/net-are-there-any-differences-between-invariantculture-and-en-us – Hans Passant Aug 31 '20 at 16:46
1 Answers
9
You can use the FormattableString.Invariant(FormattableString) Method.
Place a
using static System.FormattableString;
at the top of your code and then use like
string interpolated = Invariant($"My interpolated string {3.5:N2}");
For background information look at:

Olivier Jacot-Descombes
- 104,806
- 13
- 138
- 188