Localization and Globalization in C#: Globalization
Thursday, March 19th, 2009Like localization, globalization in .NET is easy. If you want your application to be globalization-aware you need to display all the date, time, currency and other data in the proper display format. Fortunately, every .NET Convert method has a built in IFormatProvider parameter you can use to specify the culture you want your globalization-aware data to be displayed in. In order to force yourself to use the IFormatProvider, you can use CODE_ANALYSIS in Visual Studio, or external FxCop application which does the same thing. This application inspects your code and suggest to you how you can improve it.
DateTime.Now.ToString(CultureInfo.CurrentCulture);
If the data you are working with is not going to be displayed to the user, for example, you want to save information into a file so you can load it later, you should not use the CurrentCulture as an IFormatProvider. If you save your settings using the “de-AT” culture, and then you try to load them using “en-US” culture you might end-up with the invalid data. For this purposes, you should use CultureInfo.InvariantCulture, since it is invariant to both localization and globalization settings.
DateTime.Now.ToString(CultureInfo.InvariantCulture);