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


C# ResourceManager.GetString方法代码示例

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


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

示例1: Main

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

[assembly:NeutralResourcesLanguage("en")]

public class Example
{
   public static void Main()
   {
      string[] cultureNames = { "en-US", "fr-FR", "ru-RU", "sv-SE" };
      ResourceManager rm = new ResourceManager("DateStrings",
                                               typeof(Example).Assembly);
      
      foreach (var cultureName in cultureNames) {
         CultureInfo culture = CultureInfo.CreateSpecificCulture(cultureName);
         Thread.CurrentThread.CurrentCulture = culture; 
         Thread.CurrentThread.CurrentUICulture = culture;

         Console.WriteLine("Current UI Culture: {0}", 
                           CultureInfo.CurrentUICulture.Name);
         string dateString = rm.GetString("DateStart");
         Console.WriteLine("{0} {1:M}.\n", dateString, DateTime.Now);                           
      }                                           
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:28,代码来源:ResourceManager.GetString

输出:

Current UI Culture: en-US
Today is February 03.

Current UI Culture: fr-FR
Aujourd'hui, c'est le 3 février

Current UI Culture: ru-RU
Сегодня февраля 03.

Current UI Culture: sv-SE
Today is den 3 februari.

示例2: Main

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

[assembly:NeutralResourcesLanguage("en")]

public class Example
{
   public static void Main()
   {
      Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("ru-RU");
      Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("ru-RU");
      
      string[] cultureNames = { "fr-FR", "sv-SE" };
      ResourceManager rm = new ResourceManager("DateStrings",
                                               typeof(Example).Assembly);
      
      foreach (var cultureName in cultureNames) {
         CultureInfo culture = CultureInfo.CreateSpecificCulture(cultureName);
         string dateString = rm.GetString("DateStart", culture);
         Console.WriteLine("{0}: {1} {2}.", culture.DisplayName, dateString, 
                                            DateTime.Now.ToString("M", culture));                           
         Console.WriteLine();
      }   
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:28,代码来源:ResourceManager.GetString

输出:

French (France): Aujourd'hui, c'est le 7 février.

Swedish (Sweden): Today is den 7 februari.

示例3: Main

//csc /res:StringTable.resources Test.cs


//File: Test.cs
using System;
using System.Windows.Forms;
using System.Resources;
using System.Reflection;
public class Test
{
   
    public static void Main(String[] a)
    {
        ResourceManager FormResources = new ResourceManager("StringTable", Assembly.GetExecutingAssembly());
        string          Message;
        
        Message = FormResources.GetString("Message");
        MessageBox.Show(Message);
    }
}

//resgen StringTable.txt



/* File:StringTable.txt
# String Table
#
Message = The button has been clicked.

*/
开发者ID:C#程序员,项目名称:System.Resources,代码行数:31,代码来源:ResourceManager.GetString


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