11.4 Enumerating Culture Types

 <  Day Day Up  >  

You want to access all the cultures of a given culture type.


Technique

Use the GetCultures static method defined in the CultureInfo class. This method requires a value from the CultureTypes enumerated data type. The four possible values include CultureTypes.AllCultures , which retrieves every culture defined in the .NET Framework; the CultureTypes.InstalledWin32Cultures value, which returns only the cultures that have been installed on the current system; the CultureTypes.NeutralCultures used for cultures that do not have an associated country or region; and the CultureTypes.SpecificCultures , which returns cultures that are specific to a certain country or region:

 
 public Form1() {     InitializeComponent();     // adds list of cultures to 4 different combo boxes     foreach( CultureInfo curCI in         CultureInfo.GetCultures( CultureTypes.AllCultures ))     {         cbAll.Items.Add( curCI.DisplayName );     }     foreach( CultureInfo curCI in         CultureInfo.GetCultures( CultureTypes.InstalledWin32Cultures ))     {         cbWin32.Items.Add( curCI.DisplayName );     }     foreach( CultureInfo curCI in         CultureInfo.GetCultures( CultureTypes.NeutralCultures ))     {         cbNeutral.Items.Add( curCI.DisplayName );     }     foreach( CultureInfo curCI in         CultureInfo.GetCultures( CultureTypes.SpecificCultures ))     {         cbSpecific.Items.Add( curCI.DisplayName );     } } 

Comments

Code reuse is a valuable asset. Almost as valuable is the concept of data reuse. The .NET Framework supports a vast array of cultures and their different country and regions . If you run the application created for this recipe and look at the values returned from the GetCultures method with the CultureTypes.AllCultures parameter, you'll see what we mean. We couldn't even begin to fathom having to manually enter that information in our code. Thankfully, we don't have to because it's already been done within the CultureInfo class.

Cultures work with two key pieces of information. The first is what is known as a neutral culture. A neutral culture is one that is not associated with a country or region. For instance, English is spoken in many different places around the world. Therefore, English by itself is a neutral culture. The other key piece is any associated countries or regions that use that cultural information. Continuing with the English example, there are specific cultures for the United States, Great Britain, and Zimbabwe, to name a few.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net