System.CultureInfo Class

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

NameTypeDescription
NamestringThe culture name in format languagecode2-country/regioncode2 (e.g., "en-US").
DisplayNamestringThe culture name in the language of the localized version of .NET.
TwoLetterISOLanguageNamestringISO 639-1 two-letter code for the language (e.g., "en").
ThreeLetterISOLanguageNamestringISO 639-2 three-letter code for the language (e.g., "eng").
NumberFormatNumberFormatInfoProvides numeric formatting information.
DateTimeFormatDateTimeFormatInfoProvides date and time formatting information.
TextInfoTextInfoProvides information about text case conversion.
CompareInfoCompareInfoProvides string comparison and sorting information.
IsReadOnlyboolIndicates whether the culture is read-only.
LCIDintLocale identifier for the culture.

Methods

NameSignatureDescription
GetCultureInfostatic CultureInfo GetCultureInfo(string name)Returns a read-only CultureInfo object for the specified culture name.
CreateSpecificCulturestatic CultureInfo CreateSpecificCulture(string name)Creates a specific culture that is associated with a neutral culture.
Cloneobject Clone()Creates a writable copy of the current CultureInfo object.
Equalsoverride bool Equals(object value)Determines whether two CultureInfo instances are equal.
GetHashCodeoverride int GetHashCode()Gets a hash code for the current CultureInfo object.
ToStringoverride 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"));
    }
}