访问本地化资源字符串而不创建"ResourceManager"实例?

Mar*_*tin 3 .net c# resources localization resourcemanager

我创建了一些资源文件来保存字符串.我MessageBox通过直接指向一个名为的资源文件TestLocalResource和一个资源字符串来显示一个,该资源字符串ThisIsMyTest只需引用资源字符串,如下所示:

TestLocalResource.ThisIsMyTest
Run Code Online (Sandbox Code Playgroud)

现在这看起来确实有效.但这让我想知道通过这种方式引用资源字符串,我是否总是访问默认资源文件(例如TestLocalResource.resx)而不是其德语版本(例如TestLocalResource.de-DE.resx)?

相反,我必须使用ResourceManager吗?如果是这样,怎么ResourceManager知道当前的语言(文化)?我需要明确设置它吗?

这就是我认为我需要使用的方式ResourceManager:

ResourceManager resmgr =
    new ResourceManager("MyApplication.MyResource", Assembly.GetExecutingAssembly()); 
Run Code Online (Sandbox Code Playgroud)

但我希望有一种方法可以更方便地访问本地化资源字符串.

Dan*_*rth 11

您不需要显式使用ResourceManager.
请看这里:http://geekswithblogs.net/mapfel/archive/2008/11/01/126465.aspx
要了解如何在运行时更改要使用的区域性,请参阅链接中的第二条注释:

switch (comboBox1.Text)
{
    case "neutral":
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("");
        break;
    case "en-GB":
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
        break;
    case "de-DE":
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE");
        break;
}

string messageText = Messages.MsgSampleText;
MessageBox.Show(messageText); 
Run Code Online (Sandbox Code Playgroud)