Wednesday, 22 August 2018

Introduction to CultureInfo Class

CultureInfo Class provides information about specific culture (locale). The information includes the names for the culture, the writing system, the calendar used, the sort order of strings, and formatting for dates and numbers.

Program.cs

using System;
using System.Globalization;

class Program
{
    static void Main()
    {
        foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures))
        {
            Console.WriteLine(ci);
        }
    }

}

Above program return all the cultures supported by the .net framework.

CultureInfo class provides following constructors to get the instance specific to given culture.

Constructor
Description
CultureInfo(Int32)
Initializes a new instance of the CultureInfo class based on the culture specified by the culture identifier.
CultureInfo(Int32, Boolean)
Initializes a new instance of the CultureInfo class based on the culture specified by the culture identifier and on the Boolean that specifies whether to use the user-selected culture settings from the system.
CultureInfo(String)
Initializes a new instance of the CultureInfo class based on the culture specified by name.
CultureInfo(String, Boolean)    
Initializes a new instance of the CultureInfo class based on the culture specified by name and on the Boolean that specifies whether to use the user-selected culture settings from the system.


How to set the culture to a thread
Stirng locale = "ar-YE";
CultureInfo newCulture = new CultureInfo(locale);
Thread.CurrentThread.CurrentCulture = newCulture;
Thread.CurrentThread.CurrentUICulture = newCulture;

Previous                                                 Next                                                 Home

No comments:

Post a Comment