Overview
The System.Globalization.CultureInfo
class provides information about a specific culture (language, sublanguage, country/region, calendar, and cultural conventions).
It is commonly used for formatting dates, times, numbers, and strings according to culture-specific rules.
Properties
Name | Type | Description |
---|---|---|
Name | string | The culture name in format languagecode2-country/regioncode2 (e.g., "en-US"). |
DisplayName | string | The culture name in the language of the localized version of .NET. |
TwoLetterISOLanguageName | string | ISO 639-1 two-letter code for the language (e.g., "en"). |
ThreeLetterISOLanguageName | string | ISO 639-2 three-letter code for the language (e.g., "eng"). |
NumberFormat | NumberFormatInfo | Provides numeric formatting information. |
DateTimeFormat | DateTimeFormatInfo | Provides date and time formatting information. |
TextInfo | TextInfo | Provides information about text case conversion. |
CompareInfo | CompareInfo | Provides string comparison and sorting information. |
IsReadOnly | bool | Indicates whether the culture is read-only. |
LCID | int | Locale identifier for the culture. |
Methods
Name | Signature | Description |
---|---|---|
GetCultureInfo | static CultureInfo GetCultureInfo(string name) | Returns a read-only CultureInfo object for the specified culture name. |
CreateSpecificCulture | static CultureInfo CreateSpecificCulture(string name) | Creates a specific culture that is associated with a neutral culture. |
Clone | object Clone() | Creates a writable copy of the current CultureInfo object. |
Equals | override bool Equals(object value) | Determines whether two CultureInfo instances are equal. |
GetHashCode | override int GetHashCode() | Gets a hash code for the current CultureInfo object. |
ToString | override string ToString() | Returns the culture name. |
Examples
Formatting a number according to French culture:
using System;
using System.Globalization;
class Program
{
static void Main()
{
var french = new CultureInfo("fr-FR");
double value = 12345.67;
Console.WriteLine(value.ToString("N", french));
}
}
Parsing a date string with invariant culture:
using System;
using System.Globalization;
class Demo
{
static void Main()
{
string dateString = "2023-12-15";
DateTime date = DateTime.ParseExact(dateString, "yyyy-MM-dd", CultureInfo.InvariantCulture);
Console.WriteLine(date.ToString("D"));
}
}