Questo articolo è stato tradotto automaticamente. Per visualizzare l'articolo in inglese, selezionare la casella di controllo Inglese. È possibile anche visualizzare il testo inglese in una finestra popup posizionando il puntatore del mouse sopra il testo.
Traduzione
Inglese

Costruttore CultureInfo (String, Boolean)

 

Data di pubblicazione: ottobre 2016

Inizializza una nuova istanza della classe CultureInfo in base alle impostazioni cultura specificate per nome e al valore booleano che indica se usare le impostazioni cultura del sistema selezionate dall'utente.

Spazio dei nomi:   System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

public CultureInfo(
	string name,
	bool useUserOverride
)

Parametri

name
Type: System.String

Nome CultureInfo predefinito, proprietà Name di un oggetto CultureInfo esistente o nome di impostazioni cultura solo Windows. Per name non viene effettuata la distinzione tra maiuscole e minuscole.

useUserOverride
Type: System.Boolean

Valore booleano che indica se usare le impostazioni cultura selezionate dall'utente (true) oppure quelle predefinite (false).

Exception Condition
ArgumentNullException

name è null.

CultureNotFoundException

name non è un nome di impostazioni cultura valido. Per altre informazioni, vedere la sezione Note per i chiamanti.

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 Windows culture 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.

Applications should typically not disallow user overrides. Note that disallowing overrides does not itself guarantee data stability; see the blog entry Culture data shouldn't be considered stable (except for Invariant)http://go.microsoft.com/fwlink/?LinkId=156850.

If the P:System.Globalization.CultureInfo.UseUserOverride property is set to true and the culture identifier associated with the specified culture name matches the culture identifier of the current Windows culture, this constructor creates a T:System.Globalization.CultureInfo 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.

Otherwise, this constructor creates a T:System.Globalization.CultureInfo that uses the default values for the specified culture.

The value of the useUserOverride parameter becomes the value of the P:System.Globalization.CultureInfo.UseUserOverride property.

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", true), 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("ar-SA", false), P:System.Globalization.CultureInfo.Calendar is set to T:System.Globalization.HijriCalendar (which is the default calendar for ar-SA) and P:System.Globalization.CultureInfo.UseUserOverride is set to false.

  • With CultureInfo("th-TH", true), 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.

  • With CultureInfo("th-TH", false), 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 false.

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 set the useUserOverride parameter to false.

Note per i chiamanti:

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.

.NET Framework
Disponibile da 1.1
Torna all'inizio
Mostra: