2011-05-10 92 views

回答

-1

在cs文件键入您的本地化命名空间:

Localization.Resources.KeyName 

方便快捷:)

+0

你从哪里得到本地化对象? – Muflix 2015-11-19 11:52:07

8
public string ReadResourceValue(string file, string key) 

{ 

    string resourceValue = string.Empty; 
    try 
    { 

     string resourceFile = file; 

     string filePath = System.AppDomain.CurrentDomain.BaseDirectory.ToString(); 

     ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager(resourceFile, filePath, null); 
     // retrieve the value of the specified key 
     resourceValue = resourceManager.GetString(key); 
    } 
    catch (Exception ex) 
    { 
     Console.WriteLine(ex.Message); 
     resourceValue = string.Empty; 
    } 
    return resourceValue; 
} 
3

还有一个更简单的方法:Namespace.Properties.Resources.FileName - >得到文件内容的字符串。

即:TestProject1.Properties.Resources.MyXmlFile - >直接访问文件中的资源

-1

你可以从global resourcekeyvalue这里。

//TestResource is resource class name. 

String keyValue=string.Empty; 

keyValue= Resources.TestResource.KeyString;