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?
Force string interpolation to always follow CultureInfo.InvariantCulture
Asked Answered
You can specify if string interpolation should use the invariant culture by using learn.microsoft.com/en-us/dotnet/api/… –
Tommie
#2329797 –
Ovolo
See #32077323 –
Danonorwegian
This question is similar to: String Interpolation in Visual Studio 2015 and IFormatProvider (CA1305). If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. –
Danonorwegian
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:
© 2022 - 2024 — McMap. All rights reserved.