Culture-Specific Classes for Global Windows Forms and Web Forms

Each culture has different conventions for displaying dates, time, numbers, currency, and other information. The System.Globalization namespace contains classes that can be used to modify how culture-specific values are displayed, such as DateTimeFormatInfo, Calendar, and NumberFormatInfo.

Using the Culture Setting

But most of the time you will use the culture setting, stored either in the application or in the Regional Options control panel, to automatically determine the conventions at run time and format the information accordingly. For more information on setting the culture, see How to: Set the Culture and UI Culture for Windows Forms Globalization or How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization. Classes that automatically format information according to the culture setting are called culture-specific. Some culture-specific methods are IFormattable.ToString, Console.WriteLine, and String.Format. Some culture-specific functions (in the Visual Basic language) are MonthName and WeekDayName.

For example, the following code shows how you can use the ToString method to format currency for the current culture:

' Put the Imports statements at the beginning of the code module
Imports System.Threading
Imports System.Globalization
' Display a number with the culture-specific currency formatting
Dim MyInt As Integer = 100
Console.WriteLine(MyInt.ToString("C", Thread.CurrentThread.CurrentCulture))
// Put the using statements at the beginning of the code module
using System.Threading;
using System.Globalization;
// Display a number with the culture-specific currency formatting
int myInt = 100;
Console.WriteLine(myInt.ToString("C", Thread.CurrentThread.CurrentCulture));

If the culture is set to "fr-FR", you will see this in the output window:

100,00

If the culture is set to "en-US", you will see this in the output window:

$100.00

See Also

Reference

IFormattable.ToString

DateTimeFormatInfo

NumberFormatInfo

Calendar

Console.WriteLine

String.Format

Other Resources

Globalizing and Localizing Applications