2008-05-15

How to get information about your current culture.

Instead of doing a college survery and asking a bunch of probing questions about the lives of twenty-somethings, there's an easier way to get information about your current culture. Just look at CultureInfo.CurrentCulture.

Here's a quick program that explains how to do that. This can be very useful in debugging and troubleshooting how your program behaves on machines that are setup for other laungages or regions.


using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
CultureInfo currentCulture = CultureInfo.CurrentCulture;

Console.WriteLine("CultureInfo");
Console.WriteLine("-----------");
Console.WriteLine("DisplayName: {0}", currentCulture.DisplayName);
Console.WriteLine("Name: {0}", currentCulture.Name);
Console.WriteLine("LCID: {0}", currentCulture.LCID);
Console.WriteLine();

Console.WriteLine("NumberFormatInfo");
Console.WriteLine("----------------");
Console.WriteLine("Decimal Seperator: {0}", currentCulture.NumberFormat.NumberDecimalSeparator);
Console.Write("Digits: ");

foreach (string s in currentCulture.NumberFormat.NativeDigits)
{
Console.Write(s + " ");
}

Console.WriteLine();
}
}
}




Base output should look like:


CultureInfo
-----------
DisplayName: English (United States)
Name: en-US
LCID: 1033



NumberFormatInfo
----------------
Decimal Seperator: .
Digits: 0 1 2 3 4 5 6 7 8 9

No comments: