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:
- Culture Information: Representing and querying details about specific cultures (languages, regions, calendars, etc.) using the
CultureInfo
class. - Text Encoding: Handling conversions between strings and byte arrays using various encodings, managed by the
Encoding
class and its descendants. - Text Normalization: Performing operations like case conversion, accent removal, and canonical equivalence for strings with the
TextInfo
class. - Calendar Systems: Working with different calendar systems (Gregorian, Japanese, Korean, etc.) through the
Calendar
abstract class and its concrete implementations. - Region and Language Identification: Identifying and managing regions and languages for cultural settings.
Classes and Structs
CultureInfo
- Represents information about a specific culture or language.Represents information about a specific culture or language.Calendar
- Represents a calendar system.Represents a calendar system.GregorianCalendar
- Represents the Gregorian calendar.Represents the Gregorian calendar.TextInfo
- Provides culture-sensitive information for string manipulation.Provides culture-sensitive information for string manipulation.CompareInfo
- Provides a way to compare strings based on specific culture and sort rules.Provides a way to compare strings based on specific culture and sort rules.NumberFormatInfo
- Defines the formatting of numbers for different cultures.Defines the formatting of numbers for different cultures.DateTimeFormatInfo
- Defines the format of date and time strings for different cultures.Defines the format of date and time strings for different cultures.RegionInfo
- Provides properties for retrieving information about a specific geographic region.Provides properties for retrieving information about a specific geographic region.UnicodeCategory
- Defines Unicode character categories.Defines Unicode character categories.
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)}");
}
}