I have been wondering about this for quite some time, but I cannot find a definitive answer. Whenever I convert an integer to a string using the ToString() method and I start the code analysis, I get the following warning:
CA1305: Microsoft. Globalization: since the behavior of 'int.ToString ()' could vary depending on the current user language settings, replace this call in 'Class.Method ()' with a call to 'Int.toString (IFormatProvider). If the result is' int.ToString (IFormatProvider), the user will be displayed, specify "CultureInfo.CurrentCulture" as the "IFormatProvider" Parameter. Otherwise, if the result will be stored and accessible using software, such as when saving to disk or database, specify 'CultureInfo.InvariantCulture'.
This is a very well-known general warning CA1305, which is displayed every time a method is called that has an overload that accepts the IFormatProvider parameter. Although this is an almost correct warning in almost all cases, I cannot think of anything that could go wrong when you call ToString() by default without any format or formatprovider for an integer. So please, if anyone knows anything that might go wrong, enlighten me. I assume IFormatProvider must be a good reason for overloading IFormatProvider .
BTW, I do always make a call using the IFormatProvider overload, because it also seems to have a performance advantage. If anyone has any insightful comments about this, feel free to share them.
Edwin de koning
source share