I have used double.parse a lot in my project and now found issues that other users get problems.
I should have used:
double.parse(string, CultureInfo.InvariantCulture);
everywhere.
Can I change the behavior of double.parse or do I really need to go to all places in the code and do this manually?
No, you cannot override a static method.
You will have to manually refactor your code to use the correct overload of double.Parse.
There's a possibility to override the whole application's culture by using
Application.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
in the application's main method.
So all double.Parse(string) are now equal to double.Parse(string, CultureInfo.InvariantCulture), because it uses the invariant culture internally.
But be aware that it changes EVERYTHING that uses formating.
That means, double.ToString() also uses the invariant culture.
If this is a problem, then you have to replace every occurance of double.Parse(string)
by double.Parse(string, CultureInfo.InvariantCulture)!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With