How to get information about your current culture.

Written by Troy Howard

15 May 2008

Instead of doing a college survey 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 languages or regions.

 1
 2using System; 
 3using System.Collections.Generic; 
 4using System.Text; 
 5using System.Globalization; 
 6
 7namespace ConsoleApplication1 {
 8  class Program {
 9    static void Main(string[] args) {
10      CultureInfo currentCulture = CultureInfo.CurrentCulture; 
11      
12      Console.WriteLine("CultureInfo"); 
13      Console.WriteLine("\-----------"); 
14      Console.WriteLine("DisplayName: {0}", currentCulture.DisplayName); 
15      Console.WriteLine("Name: {0}", currentCulture.Name); 
16      Console.WriteLine("LCID: {0}", currentCulture.LCID); 
17      Console.WriteLine(); 
18      
19      Console.WriteLine("NumberFormatInfo"); 
20      Console.WriteLine("\----------------"); 
21      Console.WriteLine("Decimal Seperator: {0}", currentCulture.NumberFormat.NumberDecimalSeparator); 
22      Console.Write("Digits: "); 
23      
24      foreach (string s in currentCulture.NumberFormat.NativeDigits) {
25        Console.Write(s + " "); 
26      }
27      
28      Console.WriteLine(); 
29    }
30  }
31} 

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