[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: List the defined locales in C#

locales This example is fairly straightforward. When the form loads, the following event handler lists the defined locales.

private void Form1_Load(object sender, EventArgs e) { // Make the ListBox use tabs. lstLocales.UseTabStops = true; lstLocales.UseCustomTabOffsets = true; // Define the tabs. ListBox.IntegerCollection offsets = lstLocales.CustomTabOffsets; offsets.Add(100); // Add the locale information. foreach (CultureInfo info in CultureInfo.GetCultures(CultureTypes.AllCultures)) { lstLocales.Items.Add( info.EnglishName + '\t' + info.NativeName); } // Display the number of locales. lblNumLocales.Text = lstLocales.Items.Count.ToString() + " locales"; }

The code prepares the ListBox to use tab stops. It then loops through the CultureInfo objects returned by CultureInfo.GetCultures(CultureTypes.AllCultures). For each CultureInfo object, the program adds the object's English and native names separated by a tab to the ListBox. It finishes by displaying the number of locales.

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.