asp.net.ph

CultureInfo.GetCultures Method

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 [ ];

Parameters

types
A bitwise combination of CultureTypes values that filter the cultures to retrieve.

Return Value

An array of type CultureInfo that represents the supported cultures filtered by the specified CultureTypes values. The array of cultures is unsorted.

Exceptions


Exception type Condition
ArgumentOutOfRangeException types specifies an invalid combination of CultureTypes values.

Remarks

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.

Example

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>";
}
  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 

See Also

CultureInfo Members   CultureTypes Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph