System.Globalization Namespace CultureInfo Class
Gets the list of supported cultures filtered by the specified CultureTypes.
[ VB ]
public Shared Function GetCultures ( _
ByVal types As CultureTypes _
) As CultureInfo ( )
[ C# ]
public static CultureInfo [ ] GetCultures (
CultureTypes types
);
[ C++ ]
public: static CultureInfo* GetCultures (
CultureTypes types
) [ ];
[ JScript ]
static function GetCultures (
types : CultureTypes
) : CultureInfo [ ];
- types
- A bitwise combination of CultureTypes values that filter the cultures to retrieve.
An array of type CultureInfo that represents the supported cultures filtered by the specified CultureTypes values. The array of cultures is unsorted.
Setting the types parameter to the SpecificCultures value returns all specific cultures. Setting types to the NeutralCultures value returns all neutral cultures and the invariant culture. Setting types to the AllCultures value returns all neutral and specific cultures, cultures installed in the Windows system, and custom cultures created by the user.
The folllowing example shows using GetCultures to fetch and print the names and currency formats of specific cultures.
string html;
public void Page_Load ( Object src, EventArgs e ) {
int myInt = 123456;
CultureInfo [ ] cultures = CultureInfo.GetCultures ( CultureTypes.SpecificCultures );
// write headers
html += "<table align='center' class='data' cellspacing=1>";
html += "<tr>";
html += "<th>Name</th>";
html += "<th>Native Name</th>";
html += "<th>English Name</th>";
html += "<th>Currency Format</th>";
html += "</tr>";
// list names and currency formats of available cultures
foreach ( CultureInfo culture in cultures ) {
html += "<tr>";
html += "<td>" + culture + "</td>";
html += "<td>" + culture.NativeName + "</td>";
html += "<td>" + culture.EnglishName + "</td>";
html += "<td align='right'>" + myInt.ToString ( "C", culture ) + "</td>";
html += "</tr>";
}
html += "</table>";
}
Dim html As String
Public Sub Page_Load ( sender As Object, e As EventArgs )
Dim myInt As Integer = 123456
Dim cultures As CultureInfo ( ) = CultureInfo.GetCultures ( CultureTypes.SpecificCultures )
' write headers
html += "<table align='center' class='data' cellspacing=1>"
html += "<tr>"
html += "<th>Name</th>"
html += "<th>Native Name</th>"
html += "<th>English Name</th>"
html += "<th>Currency Format</th>"
html += "</tr>"
' list names and currency formats of available cultures
Dim culture As CultureInfo
For Each culture In cultures
html += "<tr>"
html += "<td>" + culture + "</td>"
html += "<td>" + culture.NativeName + "</td>"
html += "<td>" + culture.EnglishName + "</td>"
html += "<td align='right'>" + myInt.ToString ( "C", culture ) + "</td>"
html += "</tr>"
Next culture
html += "</table>"
End Sub 'Page_Load |
|
C# |
VB |
Show me
By itself, the returned array of CultureInfo objects cannot be sorted, as the CultureInfo class does not implement the IComparable interface, which allow for type-specific comparing and sorting.
However, sorting can still be done by first copying the string equivalent of each CultureInfo object in the array into a collection that supports sorting, such as an ArrayList, and then invoking the Sort method on the ArrayList.
The below example illustrates how you can present the list of supported cultures sorted by culture name.
CultureInfo [ ] cultures = CultureInfo.GetCultures ( CultureTypes.SpecificCultures );
ArrayList strCultures = new ArrayList ( );
foreach ( CultureInfo culture in cultures ) {
strCultures.Add ( culture.ToString ( ) );
}
strCultures.Sort ( );
Show me
CultureInfo Members CultureTypes