本文整理汇总了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);
}
}
}
输出:
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();
}
}
}
输出:
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.
*/