System.Globalization.CultureInfo Class

Represents information about a specific culture (that is, a set of characteristics that uniquely define a user or machine).

Namespace: System.Globalization

Assembly: System.Runtime.dll

Inheritance Hierarchy

System.Object
System.Globalization.CultureInfo

Syntax

public sealed class CultureInfo : CultureInfo, ICloneable, IEquatable<CultureInfo>

Remarks

The CultureInfo class provides information about a specific culture, such as the language, the date and time formats, the currency format, and the sort order of strings. This information is used by various classes in the .NET Framework to format data according to the conventions of a particular culture.

You can obtain a CultureInfo object for a specific culture by using the static properties of the CultureInfo class (e.g., CultureInfo.CurrentCulture, CultureInfo.InvariantCulture) or by using the constructor.

For example, to get the CultureInfo object for U.S. English:

CultureInfo usEnglish = new CultureInfo("en-US");

The CultureInfo class also provides properties to access culture-specific information, such as:

  • DisplayName: The name displayed for the culture.
  • EnglishName: The name of the culture in English.
  • IsNeutralCulture: Indicates whether the culture is a neutral culture.
  • Parent: Gets the parent culture of the current culture.
  • TextInfo: Gets an object that provides culture-sensitive text information.
  • DateTimeFormat: Gets a DateTimeFormatInfo object that defines the date and time format for the culture.
  • NumberFormat: Gets a NumberFormatInfo object that defines the number format for the culture.

Constructor Summary

Name Description
CultureInfo(string name) Initializes a new instance of the CultureInfo class by using the specified name.
CultureInfo(string name, bool useUserOverride) Initializes a new instance of the CultureInfo class by using the specified name and a value that indicates whether to use the user-supplied culture settings.

Field Summary

No public fields.

Property Summary

Name Description
CurrentCulture Gets or sets the CultureInfo for the current thread.
CurrentUICulture Gets or sets the CultureInfo for the current UI thread.
InvariantCulture Gets a read-only CultureInfo that is culture-independent.
DisplayName Gets the name displayed for the culture.
EnglishName Gets the name of the culture in English.
IsNeutralCulture Indicates whether the culture is a neutral culture.
Name Gets the identifier of the culture.
Parent Gets the parent culture of the current culture.
TextInfo Gets an object that provides culture-sensitive text information.
DateTimeFormat Gets a DateTimeFormatInfo object that defines the date and time format for the culture.
NumberFormat Gets a NumberFormatInfo object that defines the number format for the culture.

Method Summary

Name Description
Equals(object obj) Determines whether the specified object is equal to the current object.
GetCultureInfo(string name) Retrieves a read-only CultureInfo object for the specified culture.
GetHashCode() Serves as the default hash function.

Example Usage

The following example demonstrates how to get and use culture-specific information.

using System; using System.Globalization; public class CultureInfoExample { public static void Main(string[] args) { // Get the current culture CultureInfo currentCulture = CultureInfo.CurrentCulture; Console.WriteLine($"Current Culture: {currentCulture.Name} ({currentCulture.DisplayName})"); // Get information about U.S. English culture CultureInfo usCulture = new CultureInfo("en-US"); Console.WriteLine($"\nU.S. English Culture: {usCulture.Name} ({usCulture.EnglishName})"); // Format a date according to the current culture DateTime now = DateTime.Now; Console.WriteLine($"Current Date (Current Culture): {now.ToString("d")}"); // Format a date according to U.S. English culture Console.WriteLine($"Current Date (U.S. Culture): {now.ToString("d", usCulture)}"); // Format a number according to the current culture decimal price = 1234.56m; Console.WriteLine($"Price (Current Culture): {price.ToString("C", currentCulture)}"); // Format a number according to U.S. English culture Console.WriteLine($"Price (U.S. Culture): {price.ToString("C", usCulture)}"); } }