Do any .NET cultures handle canonical representations of integers differently?
The canonical representation of an integer is as a sequence of ASCII decimal digit characters, with a prefixed '-' only if the number is negative. No initial '0' except when the number being represented is zero. No other characters, including commas, currency symbols, spaces, units, '+', decimal points, etc.
Are the any .NET cultures such that int.TryParse will return a different value to the invariant culture when given a string containing a canonical representation of an integer?
If there are none, does .NET guarantee that any culture that may be added in the future will continue to behave in this way?
Or to put it another way... Do I need to specify the invariant culture when calling int.TryParse if I only care about this variety of input?
Even the negative sign has different options depending on the culture. If you do a
var numbers = from c in CultureInfo.GetCultures(CultureTypes.AllCultures)
group c by c.NumberFormat.NumberNegativePattern into g
select g;
and then examine numbers
you will see that some cultures use a different option for the negative sign, for example the culture lo
or lo-LA
.
As a rule of thumb I use CultureInfo.InvariantCulture
for all purposes except for displaying it to the user.