System.Globalization.CultureInfo Class

Represents information about a specific culture, including the names of the culture, the calendar used, the date and time formatting, and the conventions for number formatting.

Namespace

System.Globalization

Assembly

mscorlib.dll

Inheritance

Object
System.Globalization.CultureInfo

Derived classes

Implemented interfaces

Remarks

The CultureInfo class supports a culture-sensitive processing of information. For example, when you format a date or a number, the CultureInfo object determines whether to use periods or commas as separators, and whether to display the date before or after the month.

You can obtain a CultureInfo object for a specific culture by using the static properties (like CultureInfo.CurrentCulture, CultureInfo.InvariantCulture, CultureInfo.GetCultureInfo(string name)) or by creating a new instance of the class.

Example

The following example demonstrates how to get the current culture and display its name and some formatting information:

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      // Get the current culture
      CultureInfo currentCulture = CultureInfo.CurrentCulture;

      Console.WriteLine($"Culture Name: {currentCulture.Name}");
      Console.WriteLine($"English Name: {currentCulture.EnglishName}");
      Console.WriteLine($"Native Name: {currentCulture.NativeName}");

      // Example of date formatting
      DateTime now = DateTime.Now;
      Console.WriteLine($"Current Date ({currentCulture.Name}): {now.ToString("d")}");

      // Example of number formatting
      decimal price = 1234.56m;
      Console.WriteLine($"Current Price ({currentCulture.Name}): {price.ToString("C")}");
   }
}

Methods

GetCultureInfo(string name)

public static CultureInfo GetCultureInfo(string name);

Retrieves a CultureInfo object for the specified culture name.

GetCultureInfo(int culture)

public static CultureInfo GetCultureInfo(int culture);

Retrieves a CultureInfo object for the specified culture identifier.

ToString()

public override string ToString();

Returns the culture name.

Properties

Name

public string Name { get; }

Gets the name of the culture, which is a standard 3-letter ISO 639-2 language code, preceded by an underscore and followed by a three-letter ISO 3166 country/region code.

EnglishName

public string EnglishName { get; }

Gets the full culture name in English.

NativeName

public string NativeName { get; }

Gets the full culture name in the culture's own language.

DateTimeFormat

public DateTimeFormatInfo DateTimeFormat { get; }

Gets a DateTimeFormatInfo object that defines the culture-specific format of the current DateTime object.

NumberFormat

public NumberFormatInfo NumberFormat { get; }

Gets a NumberFormatInfo object that defines the culture-specific format of the current Number object.

CurrentCulture

public static CultureInfo CurrentCulture { get; set; }

Gets or sets the globalization information for the current thread.

InvariantCulture

public static CultureInfo InvariantCulture { get; }

Gets a CultureInfo object that is culture-independent.

See also