|
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
|
Tradução
Original
|
Classe CultureInfo
Namespace: System.Globalization
Assembly: mscorlib (em mscorlib.dll)
O tipo CultureInfo expõe os membros a seguir.
| Nome | Descrição | |
|---|---|---|
![]() ![]() | CultureInfo(Int32) | |
![]() ![]() ![]() ![]() | CultureInfo(String) | |
![]() ![]() | CultureInfo(Int32, Boolean) | |
![]() ![]() | CultureInfo(String, Boolean) |
| Nome | Descrição | |
|---|---|---|
![]() ![]() ![]() ![]() | Calendar | |
![]() ![]() ![]() ![]() | CompareInfo | |
![]() | CultureTypes | |
![]() ![]() ![]() ![]() ![]() | CurrentCulture | |
![]() ![]() ![]() ![]() ![]() | CurrentUICulture | |
![]() ![]() ![]() ![]() | DateTimeFormat | |
![]() ![]() ![]() | DefaultThreadCurrentCulture | |
![]() ![]() ![]() | DefaultThreadCurrentUICulture | |
![]() ![]() ![]() | DisplayName | |
![]() ![]() ![]() ![]() | EnglishName | |
![]() | IetfLanguageTag | |
![]() ![]() | InstalledUICulture | |
![]() ![]() ![]() ![]() ![]() | InvariantCulture | |
![]() ![]() ![]() ![]() | IsNeutralCulture | |
![]() ![]() ![]() ![]() | IsReadOnly | |
![]() | KeyboardLayoutId | |
![]() ![]() | LCID | |
![]() ![]() ![]() ![]() | Name | |
![]() ![]() ![]() ![]() | NativeName | |
![]() ![]() ![]() ![]() | NumberFormat | |
![]() ![]() ![]() ![]() | OptionalCalendars | |
![]() ![]() ![]() ![]() | Parent | |
![]() ![]() ![]() ![]() | TextInfo | |
![]() ![]() | ThreeLetterISOLanguageName | |
![]() ![]() | ThreeLetterWindowsLanguageName | |
![]() ![]() ![]() ![]() | TwoLetterISOLanguageName | |
![]() ![]() | UseUserOverride |
| Nome | Descrição | |
|---|---|---|
![]() ![]() | ClearCachedData | |
![]() ![]() ![]() ![]() | Clone | |
![]() ![]() ![]() | CreateSpecificCulture | |
![]() ![]() ![]() ![]() | Equals | |
![]() ![]() ![]() ![]() | Finalize | |
![]() | GetConsoleFallbackUICulture | |
![]() ![]() ![]() | GetCultureInfo(Int32) | |
![]() ![]() ![]() | GetCultureInfo(String) | |
![]() ![]() | GetCultureInfo(String, String) | |
![]() ![]() | GetCultureInfoByIetfLanguageTag | |
![]() ![]() | GetCultures | |
![]() ![]() ![]() ![]() | GetFormat | |
![]() ![]() ![]() ![]() | GetHashCode | |
![]() ![]() ![]() ![]() | GetType | |
![]() ![]() ![]() ![]() | MemberwiseClone | |
![]() ![]() ![]() ![]() ![]() | ReadOnly | |
![]() ![]() ![]() ![]() | ToString |
Nomes e identificadores de cultura
Observação |
|---|
Observação |
|---|
Culturas invariável, neutras, e específicas
Culturas personalizadas
Culturas novas que suplementam culturas disponíveis no windows ou no .NET Framework. Por exemplo, um aplicativo pode instalar um objeto de CultureInfo que representa as FJ- FJ (ou)) Fijan (Fiji cultura em um sistema. As culturas de substituição cujas propriedades são diferentes de propriedades das culturas padrão suportado pelo windows e Framework.NET. Culturas padrão com substituição do usuário. o usuário pode usar o aplicativo de Região e Idioma em Painel de controle personalizar os valores de propriedade existentes de uma cultura.
Observação |
|---|
As culturas personalizadas podem ter valores que excedem os intervalos culturas predefinidas. Por exemplo, algumas culturas raramente têm nomes longo do mês, inesperados formatos de data ou hora, ou outros dados incomuns. Quando você exibe dados específicos de cultura de interface do usuário, você deve respeitar personalizações do usuário; por exemplo, o usuário pode querer um relógio de 24 horas ou um formato de data de yyyyMMdd. Lembre-se de que as culturas personalizadas substituem os valores padrão. Portanto, você não pode considerar dados de cultura para ser estável. Os nomes, o número e formatos de data, e as grafias do país pode ser alterado no futuro. Se você deseja serializar os dados que levam como cadeias de caracteres de data e hora a ser passada a funções de análise de data e hora, você deve usar a cultura invariável ou cadeia de caracteres de formato personalizadoespecífico.
Dados dinâmicos de cultura
Cuidado |
|---|
Cultura e segmentos
using System; using System.Globalization; using System.Threading; public class Example { static Random rnd = new Random(); public static void Main() { if (Thread.CurrentThread.CurrentCulture.Name != "fr-FR") { // If current culture is not fr-FR, set culture to fr-FR. Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR"); Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR"); } else { // Set culture to en-US. Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("en-US"); } ThreadProc(); Thread worker = new Thread(ThreadProc); worker.Name = "WorkerThread"; worker.Start(); } private static void DisplayThreadInfo() { Console.WriteLine("\nCurrent Thread Name: '{0}'", Thread.CurrentThread.Name); Console.WriteLine("Current Thread Culture/UI Culture: {0}/{1}", Thread.CurrentThread.CurrentCulture.Name, Thread.CurrentThread.CurrentUICulture.Name); } private static void DisplayValues() { // Create new thread and display three random numbers. Console.WriteLine("Some currency values:"); for (int ctr = 0; ctr <= 3; ctr++) Console.WriteLine(" {0:C2}", rnd.NextDouble() * 10); } private static void ThreadProc() { DisplayThreadInfo(); DisplayValues(); } } // The example displays output similar to the following: // Current Thread Name: '' // Current Thread Culture/UI Culture: fr-FR/fr-FR // Some currency values: // 8,11 € // 1,48 € // 8,99 € // 9,04 € // // Current Thread Name: 'WorkerThread' // Current Thread Culture/UI Culture: en-US/en-US // Some currency values: // $6.72 // $6.35 // $2.90 // $7.72
using System; using System.Globalization; using System.Threading; public class Example { static Random rnd = new Random(); public static void Main() { if (Thread.CurrentThread.CurrentCulture.Name != "fr-FR") { // If current culture is not fr-FR, set culture to fr-FR. Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR"); Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR"); } else { // Set culture to en-US. Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("en-US"); } DisplayThreadInfo(); DisplayValues(); Thread worker = new Thread(Example.ThreadProc); worker.Name = "WorkerThread"; worker.Start(Thread.CurrentThread.CurrentCulture); } private static void DisplayThreadInfo() { Console.WriteLine("\nCurrent Thread Name: '{0}'", Thread.CurrentThread.Name); Console.WriteLine("Current Thread Culture/UI Culture: {0}/{1}", Thread.CurrentThread.CurrentCulture.Name, Thread.CurrentThread.CurrentUICulture.Name); } private static void DisplayValues() { // Create new thread and display three random numbers. Console.WriteLine("Some currency values:"); for (int ctr = 0; ctr <= 3; ctr++) Console.WriteLine(" {0:C2}", rnd.NextDouble() * 10); } private static void ThreadProc(Object obj) { Thread.CurrentThread.CurrentCulture = (CultureInfo) obj; Thread.CurrentThread.CurrentUICulture = (CultureInfo) obj; DisplayThreadInfo(); DisplayValues(); } } // The example displays output similar to the following: // Current Thread Name: '' // Current Thread Culture/UI Culture: fr-FR/fr-FR // Some currency values: // 6,83 € // 3,47 € // 6,07 € // 1,70 € // // Current Thread Name: 'WorkerThread' // Current Thread Culture/UI Culture: fr-FR/fr-FR // Some currency values: // 9,54 € // 9,50 € // 0,58 € // 6,91 €
using System; using System.Globalization; using System.Threading; public class Example { static Random rnd = new Random(); public static void Main() { if (Thread.CurrentThread.CurrentCulture.Name != "fr-FR") { // If current culture is not fr-FR, set culture to fr-FR. CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR"); CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR"); } else { // Set culture to en-US. CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture("en-US"); } ThreadProc(); Thread worker = new Thread(Example.ThreadProc); worker.Name = "WorkerThread"; worker.Start(); } private static void DisplayThreadInfo() { Console.WriteLine("\nCurrent Thread Name: '{0}'", Thread.CurrentThread.Name); Console.WriteLine("Current Thread Culture/UI Culture: {0}/{1}", Thread.CurrentThread.CurrentCulture.Name, Thread.CurrentThread.CurrentUICulture.Name); } private static void DisplayValues() { // Create new thread and display three random numbers. Console.WriteLine("Some currency values:"); for (int ctr = 0; ctr <= 3; ctr++) Console.WriteLine(" {0:C2}", rnd.NextDouble() * 10); } private static void ThreadProc() { DisplayThreadInfo(); DisplayValues(); } } // The example displays output similar to the following: // Current Thread Name: '' // Current Thread Culture/UI Culture: fr-FR/fr-FR // Some currency values: // 6,83 € // 3,47 € // 6,07 € // 1,70 € // // Current Thread Name: 'WorkerThread' // Current Thread Culture/UI Culture: fr-FR/fr-FR // Some currency values: // 9,54 € // 9,50 € // 0,58 € // 6,91 €
Cuidado |
|---|
Cultura e domínios de aplicativo
using System; using System.Globalization; using System.Reflection; using System.Threading; public class Example { public static void Main() { // Set the default culture and display the current date in the current application domain. Info info1 = new Info(); SetAppDomainCultures("fr-FR"); // Create a second application domain. AppDomainSetup setup = new AppDomainSetup(); setup.AppDomainInitializer = SetAppDomainCultures; setup.AppDomainInitializerArguments = new string[] { "ru-RU" }; AppDomain domain = AppDomain.CreateDomain("Domain2", null, setup); // Create an Info object in the new application domain. Info info2 = (Info) domain.CreateInstanceAndUnwrap(typeof(Example).Assembly.FullName, "Info"); // Execute methods in the two application domains. info2.DisplayDate(); info2.DisplayCultures(); info1.DisplayDate(); info1.DisplayCultures(); } public static void SetAppDomainCultures(string[] names) { SetAppDomainCultures(names[0]); } public static void SetAppDomainCultures(string name) { try { CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture(name); CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture(name); } // If an exception occurs, we'll just fall back to the system default. catch (CultureNotFoundException) { return; } catch (ArgumentException) { return; } } } public class Info : MarshalByRefObject { public void DisplayDate() { Console.WriteLine("Today is {0:D}", DateTime.Now); } public void DisplayCultures() { Console.WriteLine("Application domain is {0}", AppDomain.CurrentDomain.Id); Console.WriteLine("Default Culture: {0}", CultureInfo.DefaultThreadCurrentCulture); Console.WriteLine("Default UI Culture: {0}", CultureInfo.DefaultThreadCurrentUICulture); } } // The example displays the following output: // Today is 14 октября 2011 г. // Application domain is 2 // Default Culture: ru-RU // Default UI Culture: ru-RU // Today is vendredi 14 octobre 2011 // Application domain is 1 // Default Culture: fr-FR // Default UI Culture: fr-FR
Serialização de objetos de CultureInfo
Se o valor da propriedade de CultureTypes é CultureTypes.WindowsOnlyCultures, e se aquela cultura foi introduzida primeiro no Windows Vista ou em uma versão posterior do sistema operacional Windows, não é possível de- para serializá-lo no Windows XP. De a mesma forma, se a cultura foi introduzida primeiro no Windows XP Service Pack 2, não é possível de- para serializá-lo para um sistema do Windows XP em que a cultura não foi instalada. Se o valor de CultureTypes é CultureTypes.UserCustomCulture, e o computador no qual de- é serializado não tem esta cultura personalizado do usuário instalada, não é possível de- serializar-la. Se o valor de CultureTypes é CultureTypes.ReplacementCultures, e o computador no qual de- é serializado não tem esta cultura de substituição, de- serializa ao mesmo nome, mas não todas as mesmas características. Por exemplo, se en-us. U. é uma cultura de substituição no computador A, mas não no computador B, e se um objeto de CultureInfo que se refere à cultura é serializado no computador e A de- serializada no computador B, então em quaisquer das características personalizados de cultura são passados. a cultura de-serializa com êxito, mas com um significado diferente.
Substituições do painel de controle
Ordem de classificação alternativos
using System; using System.Collections; using System.Globalization; public class SamplesCultureInfo { public static void Main() { // Creates and initializes the CultureInfo which uses the international sort. CultureInfo myCIintl = new CultureInfo("es-ES", false); // Creates and initializes the CultureInfo which uses the traditional sort. CultureInfo myCItrad = new CultureInfo(0x040A, false); // Displays the properties of each culture. Console.WriteLine("{0,-31}{1,-47}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL"); Console.WriteLine("{0,-31}{1,-47}{2,-25}", "CompareInfo", myCIintl.CompareInfo, myCItrad.CompareInfo); Console.WriteLine("{0,-31}{1,-47}{2,-25}", "DisplayName", myCIintl.DisplayName, myCItrad.DisplayName); Console.WriteLine("{0,-31}{1,-47}{2,-25}", "EnglishName", myCIintl.EnglishName, myCItrad.EnglishName); Console.WriteLine("{0,-31}{1,-47}{2,-25}", "IsNeutralCulture", myCIintl.IsNeutralCulture, myCItrad.IsNeutralCulture); Console.WriteLine("{0,-31}{1,-47}{2,-25}", "IsReadOnly", myCIintl.IsReadOnly, myCItrad.IsReadOnly); Console.WriteLine("{0,-31}{1,-47}{2,-25}", "LCID", myCIintl.LCID, myCItrad.LCID); Console.WriteLine("{0,-31}{1,-47}{2,-25}", "Name", myCIintl.Name, myCItrad.Name); Console.WriteLine("{0,-31}{1,-47}{2,-25}", "NativeName", myCIintl.NativeName, myCItrad.NativeName); Console.WriteLine("{0,-31}{1,-47}{2,-25}", "Parent", myCIintl.Parent, myCItrad.Parent); Console.WriteLine("{0,-31}{1,-47}{2,-25}", "TextInfo", myCIintl.TextInfo, myCItrad.TextInfo); Console.WriteLine("{0,-31}{1,-47}{2,-25}", "ThreeLetterISOLanguageName", myCIintl.ThreeLetterISOLanguageName, myCItrad.ThreeLetterISOLanguageName); Console.WriteLine("{0,-31}{1,-47}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl.ThreeLetterWindowsLanguageName, myCItrad.ThreeLetterWindowsLanguageName); Console.WriteLine("{0,-31}{1,-47}{2,-25}", "TwoLetterISOLanguageName", myCIintl.TwoLetterISOLanguageName, myCItrad.TwoLetterISOLanguageName); Console.WriteLine(); // Compare two strings using myCIintl. Console.WriteLine("Comparing \"llegar\" and \"lugar\""); Console.WriteLine(" With myCIintl.CompareInfo.Compare: {0}", myCIintl.CompareInfo.Compare("llegar", "lugar")); Console.WriteLine(" With myCItrad.CompareInfo.Compare: {0}", myCItrad.CompareInfo.Compare("llegar", "lugar")); } } /* This code produces the following output. PROPERTY INTERNATIONAL TRADITIONAL CompareInfo CompareInfo - es-ES CompareInfo - es-ES_tradnl DisplayName Spanish (Spain) Spanish (Spain) EnglishName Spanish (Spain, International Sort) Spanish (Spain, Traditional Sort) IsNeutralCulture False False IsReadOnly False False LCID 3082 1034 Name es-ES es-ES NativeName Español (España, alfabetización internacional) Español (España, alfabetización tradicional) Parent es es TextInfo TextInfo - es-ES TextInfo - es-ES_tradnl ThreeLetterISOLanguageName spa spa ThreeLetterWindowsLanguageName ESN ESP TwoLetterISOLanguageName es es Comparing "llegar" and "lugar" With myCIintl.CompareInfo.Compare: -1 With myCItrad.CompareInfo.Compare: 1 */
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Função Server Core sem suporte), Windows Server 2008 R2 (Função Server Core com suporte com o SP1 ou posterior, Itanium sem suporte)
O .NET Framework não oferece suporte a todas as versões de cada plataforma. Para obter uma lista das versões com suporte, consulte .Requisitos de sistema do NET Framework.


