Culture-Specific Classes for Global Windows Forms and Web Forms

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

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 System.IFormattable.ToString, System.Console.WriteLine, and System.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

System.IFormattable.ToString DateTimeFormatInfo NumberFormatInfo Calendar System.Console.WriteLine System.String.Format Globalizing and Localizing Applications