当前位置: 首页>>代码示例>>C#>>正文


C# CultureInfo.CurrentCulture属性代码示例

本文整理汇总了C#中System.Globalization.CultureInfo.CurrentCulture属性的典型用法代码示例。如果您正苦于以下问题:C# CultureInfo.CurrentCulture属性的具体用法?C# CultureInfo.CurrentCulture怎么用?C# CultureInfo.CurrentCulture使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.Globalization.CultureInfo的用法示例。


在下文中一共展示了CultureInfo.CurrentCulture属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
using System;
using System.Globalization;
using System.Threading;

public class Example
{
   public static void Main()  
   {
      // Display the name of the current thread culture.
      Console.WriteLine("CurrentCulture is {0}.", CultureInfo.CurrentCulture.Name);

      // Change the current culture to th-TH.
      CultureInfo.CurrentCulture = new CultureInfo("th-TH", false);
      Console.WriteLine("CurrentCulture is now {0}.", CultureInfo.CurrentCulture.Name);

      // Display the name of the current UI culture.
      Console.WriteLine("CurrentUICulture is {0}.", CultureInfo.CurrentUICulture.Name);

      // Change the current UI culture to ja-JP.
      CultureInfo.CurrentUICulture = new CultureInfo( "ja-JP", false );
      Console.WriteLine("CurrentUICulture is now {0}.", CultureInfo.CurrentUICulture.Name);
   }
}
开发者ID:.NET开发者,项目名称:System.Globalization,代码行数:24,代码来源:CultureInfo.CurrentCulture

输出:

CurrentCulture is en-US.
CurrentCulture is now th-TH.
CurrentUICulture is en-US.
CurrentUICulture is now ja-JP.

示例2: Main

//引入命名空间
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;

[assembly:TargetFramework(".NETFramework,Version=v4.6")]

public class Example
{
   public static async Task Main()
   {
      var tasks = new List<Task>();
      Console.WriteLine("The current culture is {0}", 
                        Thread.CurrentThread.CurrentCulture.Name);
      Thread.CurrentThread.CurrentCulture = new CultureInfo("pt-BR");
      // Change the current culture to Portuguese (Brazil).
      Console.WriteLine("Current culture changed to {0}",
                        Thread.CurrentThread.CurrentCulture.Name);
      Console.WriteLine("Application thread is thread {0}",
                        Thread.CurrentThread.ManagedThreadId);
      // Launch six tasks and display their current culture.
      for (int ctr = 0; ctr <= 5; ctr++)
         tasks.Add(Task.Run( () => {
                               Console.WriteLine("Culture of task {0} on thread {1} is {2}",
                                                 Task.CurrentId, 
                                                 Thread.CurrentThread.ManagedThreadId,
                                                 Thread.CurrentThread.CurrentCulture.Name);
                            } ));                     

      await Task.WhenAll(tasks.ToArray());
   }
}
开发者ID:.NET开发者,项目名称:System.Globalization,代码行数:35,代码来源:CultureInfo.CurrentCulture

输出:

The current culture is en-US
Current culture changed to pt-BR
Application thread is thread 9
Culture of task 2 on thread 11 is pt-BR
Culture of task 1 on thread 10 is pt-BR
Culture of task 3 on thread 11 is pt-BR
Culture of task 5 on thread 11 is pt-BR
Culture of task 6 on thread 11 is pt-BR
Culture of task 4 on thread 10 is pt-BR

示例3: Main

//引入命名空间
using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CultureInfo culture = CultureInfo.CurrentCulture;
      Console.WriteLine("The current culture is {0} [{1}]",
                        culture.NativeName, culture.Name);
   }
}
开发者ID:.NET开发者,项目名称:System.Globalization,代码行数:13,代码来源:CultureInfo.CurrentCulture

输出:

The current culture is English (United States) [en-US]

示例4: ShowCurrentCulture

//引入命名空间
using System;
using System.Globalization;
using System.Threading;

public class Info : MarshalByRefObject
{
   public void ShowCurrentCulture()
   {
      Console.WriteLine("Culture of {0} in application domain {1}: {2}",
                        Thread.CurrentThread.Name,
                        AppDomain.CurrentDomain.FriendlyName,
                        CultureInfo.CurrentCulture.Name);
   }
}

public class Example
{
   public static void Main()
   {
      Info inf = new Info();
      // Set the current culture to Dutch (Netherlands).
      Thread.CurrentThread.Name = "MainThread";
      CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("nl-NL");
      inf.ShowCurrentCulture();
      
      // Create a new application domain.
       AppDomain ad = AppDomain.CreateDomain("Domain2");
       Info inf2 = (Info) ad.CreateInstanceAndUnwrap(typeof(Info).Assembly.FullName, "Info");
       inf2.ShowCurrentCulture();                       
   }
}
开发者ID:.NET开发者,项目名称:System.Globalization,代码行数:32,代码来源:CultureInfo.CurrentCulture

输出:

Culture of MainThread in application domain ChangeCulture1.exe: nl-NL
Culture of MainThread in application domain Domain2: nl-NL

示例5: Main

//引入命名空间
using System;
using System.Globalization;
using System.Threading;

public class Example
{
   public static void Main()
   {
      double value = 1634.92;
      CultureInfo.CurrentCulture = new CultureInfo("fr-CA");
      Console.WriteLine("Current Culture: {0}", 
                        CultureInfo.CurrentCulture.Name);
      Console.WriteLine("{0:C2}\n", value);
      
      Thread.CurrentThread.CurrentCulture = new CultureInfo("fr");
      Console.WriteLine("Current Culture: {0}", 
                        CultureInfo.CurrentCulture.Name);
      Console.WriteLine("{0:C2}", value);
   }
}
开发者ID:.NET开发者,项目名称:System.Globalization,代码行数:21,代码来源:CultureInfo.CurrentCulture

输出:

Current Culture: fr-CA
1 634,92 $

Current Culture: fr
1 634,92 €

示例6: Main

//引入命名空间
using System;

using System.Globalization;

class MainClass
{
  static void Main(string[] args)
  {  
      int theInt = 0;    
    Console.WriteLine("IConvertible-ing System.Int32 to System.Byte");
    IConvertible itfConvert = (IConvertible)theInt;
    byte theByte = itfConvert.ToByte(CultureInfo.CurrentCulture);
    Console.WriteLine("Type code int converted to byte is: {0}", theByte.GetTypeCode());
    Console.WriteLine("Value of converted int: {0}", theByte);
  }
}
开发者ID:C#程序员,项目名称:System.Globalization,代码行数:17,代码来源:CultureInfo.CurrentCulture


注:本文中的System.Globalization.CultureInfo.CurrentCulture属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。