ReSharper 2016.2 Help

Code Inspection: Specify string culture explicitly

Ad-hoc conversion of data structures to text is largely dependent on the current culture, and may lead to unintended results when the code is executed on a machine whose locale differs from that of the original developer. To prevent ambiguities, ReSharper warns you of any instances in code where such a problem may occur.

For example, take the following code

int x; // some statements DoSomething(x.ToString());

While one might think that an int is culture-invariant, this is in fact not the case: for example, in this case, the negative sign that gets rendered if the value is negative can be different depending on culture (this value can also be customized via the Region and Language settings in Windows). As a result, it often makes sense to specify either a specific culture (e.g., the Thread.CurrentThread.CurrentCulture) or an invariant culture (CultureInfo.InvariantCulture) for string conversions.

See Also

Last modified: 15 December 2016