I think I understand the CultureInfo usage.
If I do simple :
const int a = 5;
string b = a.ToString();
is it equal to :
const int a = 5;
string b = a.ToString(CultureInfo.InvariantCulture);
In other words, does ToString() by default use InvariantCulture or CurrentCulture or neither ?
The invariant culture is culture-insensitive; it is associated with the English language but not with any country/region. You specify the invariant culture by name by using an empty string ("") in the call to a CultureInfo instantiation method. CultureInfo.
The CultureInfo class provides culture-specific information, such as the language, sublanguage, country/region, calendar, and conventions associated with a particular culture. This class also provides access to culture-specific instances of the DateTimeFormatInfo, NumberFormatInfo, CompareInfo, and TextInfo objects.
ToString
will use CurrentCulture
, not InvariantCulture
if you do not specify a culture.
ToString() uses CurrentCulture when not specified
See: http://msdn.microsoft.com/en-us/library/6t7dwaa5(v=vs.85).aspx
"The return value is formatted with the general numeric format specifier ("G") and the NumberFormatInfo for the current culture."
The ToString
implementation of all built-in classes and numeric types uses by default the CultureInfo.CurrentCulture
culture, the culture used by the current thread.
This means that the current culture (and therefore your string formatting and parsing functions) will be different from one system to another. In my opinion this is a design mistake, and it has bitten people in the past. It should have defaulted to InvariantCulture
and give the same results across systems, but unfortunately it doesn't.
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