The Windows system contains data from more than 200 countries and regions, and sometimes programming requires this information. The following code can help you get this information quickly.
The console statement is commented out and the analysis can be done faster.
1 Static voidMain (string[] args) {2Console.WriteLine ("start!");3 //Here you can modify the file path and file name. 4 varSW =NewStreamWriter (NewFileStream ("RegionInfo.txt", FileMode.OpenOrCreate)); 5 6 //get the properties of the RegionInfo class by reflection, write to the file stream as a caption7Sw. WriteLine ("Culture,"+string. Join (",",typeof(RegionInfo). GetProperties (). Select (p =p.name). ToArray ()));8 9 //defining country and region information in Windows systems use the Culture parameter, which contains 2-bit country codes and 2-bit area codesTen for(vari =0x00; I <0xFF; i++) { One for(varj =0x00; J <0xFF; J + +) { A varCulture = (I <<8) + J;//build the Culture parameter, I is the country code, J is the region code -RegionInfo ri =NULL; - //not all of the Culture parameters are valid parameters, so you need to handle instantiating exceptions the Try { -RI =NewRegionInfo (culture); - //gets the property value of the instantiated object by reflection and writes to the file stream -Sw. WriteLine (Culture +","+string. Join (",", RI. GetType (). GetProperties (). Select (p = P.getvalue (ri,NULL). ToString ()). ToArray ())); +Console.WriteLine ("0x{0:x}\tdone!", culture); -}Catch { + Continue; A } at } - } - SW. Flush (); - SW. Close (); -Console.WriteLine ("All done!"); - Console.readkey (); in}
In addition to the RegionInfo class contains country and region information in C #, the CultureInfo class also contains other information related to language, text, etc., and can be substituted for analysis by itself.
This article from the Flying Dust Blog, reproduced please indicate the source.
Quick access to country and region information on Windows systems