Este artigo foi traduzido por máquina. Para visualizar o arquivo em inglês, marque a caixa de seleção Inglês. Você também pode exibir o texto Em inglês em uma janela pop-up, movendo o ponteiro do mouse sobre o texto.
Tradução
Inglês

Construtor CultureInfo (String)

 

Inicializa uma nova instância da classe CultureInfo com base na cultura especificada por nome.

Namespace:   System.Globalization
Assembly:  mscorlib (em mscorlib.dll)

public CultureInfo(
	string name
)

Parâmetros

name
Type: System.String

Um nome de CultureInfo predefinido, Name de um CultureInfo existente, ou o nome da cultura somente do Windows. name não diferencia maiúsculas de minúsculas.

Exception Condition
ArgumentNullException

name é nulo.

CultureNotFoundException

name não é um nome de cultura válido. Para obter mais informações, consulte a seção Observações para Chamadores.

For a list of predefined culture names, see the National Language Support (NLS) API Referencehttp://go.microsoft.com/fwlink/?LinkId=200048 at the Go Global Developer Center. In addition, starting with Windows 10, name can be any valid BCP-47 language tag.

If name is F:System.String.Empty, the constructor creates an instance of the invariant culture; this is equivalent to retrieving the value of the P:System.Globalization.CultureInfo.InvariantCulture property.

The user might choose to override some of the values associated with the current culture of Windows through the regional and language options portion of Control Panel. For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture. If the culture identifier associated with name matches the culture identifier of the current Windows culture, this constructor creates a T:System.Globalization.CultureInfo object that uses those overrides, including user settings for the properties of the T:System.Globalization.DateTimeFormatInfo instance returned by the P:System.Globalization.CultureInfo.DateTimeFormat property, and the properties of the T:System.Globalization.NumberFormatInfo instance returned by the P:System.Globalization.CultureInfo.NumberFormat property. If the user settings are incompatible with the culture associated with the T:System.Globalization.CultureInfo, for example, if the selected calendar is not one of the P:System.Globalization.CultureInfo.OptionalCalendars, the results of the methods and the values of the properties are undefined.

If the culture identifier associated with name does not match the culture identifier of the current Windows culture, this constructor creates a T:System.Globalization.CultureInfo object that uses the default values for the specified culture.

The P:System.Globalization.CultureInfo.UseUserOverride property is always set to true.

For example, suppose that Arabic (Saudi Arabia) is the current culture of Windows and the user changed the calendar from Hijri to Gregorian.

  • With CultureInfo("ar-SA"), P:System.Globalization.CultureInfo.Calendar is set to T:System.Globalization.GregorianCalendar (which is the user setting) and P:System.Globalization.CultureInfo.UseUserOverride is set to true.

  • With CultureInfo("th-TH"), P:System.Globalization.CultureInfo.Calendar is set to T:System.Globalization.ThaiBuddhistCalendar (which is the default calendar for th-TH) and P:System.Globalization.CultureInfo.UseUserOverride is set to true.

The P:System.Globalization.CultureInfo.LCID property of the new T:System.Globalization.CultureInfo is set to the culture identifier associated with the specified name.

For cultures that use the euro, the .NET Framework and Windows XP set the default currency as euro. However, older versions of Windows do not do this. Therefore, if the user of an older version of Windows has not changed the currency setting through the regional and language options portion of Control Panel, the currency might be incorrect. To use the .NET Framework default setting for the currency, the application should use a T:System.Globalization.CultureInfo constructor overload that accepts a useUserOverride parameter and set it to false.

Observações para os Autores de Chamada:

The net_v35_long and earlier versions throw an T:System.ArgumentException if name is not a valid culture name. Starting with the net_v40_long, this constructor throws a T:System.Globalization.CultureNotFoundException. Starting with apps that run under the net_v40_long or later on Windows 7 or later, the method attempts to retrieve a T:System.Globalization.CultureInfo object whose identifier is name from the operating system; if the operating system does not support that culture, and if name is not the name of a supplementary or replacement culture, the method throws a T:System.Globalization.CultureNotFoundException exception.

The following example retrieves the current culture. If it is anything other than the French (France) culture, it calls the M:System.Globalization.CultureInfo.#ctor(System.String) constructor to instantiate a T:System.Globalization.CultureInfo object that represents the French (France) culture and makes it the current thread culture. Otherwise, it instantiates a T:System.Globalization.CultureInfo object that represents the French (Luxembourg) culture and makes it the current culture.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CultureInfo current = CultureInfo.CurrentCulture;
      Console.WriteLine("The current culture is {0}", current.Name);
      CultureInfo newCulture;
      if (current.Name.Equals("fr-FR"))
         newCulture = new CultureInfo("fr-LU");
      else   
         newCulture = new CultureInfo("fr-FR");

      CultureInfo.CurrentCulture = newCulture;
      Console.WriteLine("The current culture is now {0}", 
                        CultureInfo.CurrentCulture.Name);   
   }
}
// The example displays output like the following:
//     The current culture is en-US
//     The current culture is now fr-FR

Plataforma Universal do Windows
Disponível desde 8
.NET Framework
Disponível desde 1.1
Biblioteca de Classes Portátil
Com suporte no: plataformas portáteis do .NET
Silverlight
Disponível desde 2.0
Windows Phone Silverlight
Disponível desde 7.0
Windows Phone
Disponível desde 8.1
Retornar ao início
Mostrar: