System.Globalization Namespace

Provides classes that define culture-insensitive or culture-sensitive information.

Namespace: System.Globalization

Assembly: mscorlib (in mscorlib.dll)

Summary

The System.Globalization namespace contains classes that represent culture-specific information, such as character collation, number formatting, and date/time formatting. It allows applications to adapt their behavior and output to the conventions of different regions and languages.

Key types in this namespace enable:

Classes and Structs

Usage Examples

Here's a simple example demonstrating how to get culture-specific number formatting:

using System;
using System.Globalization;

public class GlobalizationExample
{
    public static void Main(string[] args)
    {
        double value = 12345.67;

        // Get formatting for the current culture
        CultureInfo currentCulture = CultureInfo.CurrentCulture;
        Console.WriteLine($"Current Culture: {currentCulture.DisplayName}");
        Console.WriteLine($"Formatted Number: {value.ToString("N2", currentCulture)}");

        // Get formatting for a specific culture (e.g., French)
        CultureInfo frenchCulture = new CultureInfo("fr-FR");
        Console.WriteLine($"French Culture: {frenchCulture.DisplayName}");
        Console.WriteLine($"Formatted Number: {value.ToString("N2", frenchCulture)}");

        // Get formatting for a specific culture (e.g., German)
        CultureInfo germanCulture = new CultureInfo("de-DE");
        Console.WriteLine($"German Culture: {germanCulture.DisplayName}");
        Console.WriteLine($"Formatted Number: {value.ToString("N2", germanCulture)}");
    }
}

Related Topics