Code inspection: Specify string culture explicitly
Last modified: 11 February 2024tip
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
While one might think that a float
is culture-invariant, this is in fact not the case: for example, the decimal separator can be different depending on culture. As a result, it often makes sense to specify either a specific culture (for example, the Thread.CurrentThread.CurrentCulture
) or an invariant culture CultureInfo.InvariantCulture
for string conversions.