read string from .resx file in C#

前端 未结 14 2100
一生所求
一生所求 2020-12-02 06:01

How to read the string from .resx file in c#? please send me guidelines . step by step

相关标签:
14条回答
  • 2020-12-02 06:50

    This example is from the MSDN page on ResourceManager.GetString():

    // Create a resource manager to retrieve resources.
    ResourceManager rm = new ResourceManager("items", Assembly.GetExecutingAssembly());
    
    // Retrieve the value of the string resource named "welcome".
    // The resource manager will retrieve the value of the  
    // localized resource using the caller's current culture setting.
    String str = rm.GetString("welcome");
    
    0 讨论(0)
  • 2020-12-02 06:51

    I added the .resx file via Visual Studio. This created a designer.cs file with properties to immediately return the value of any key I wanted. For example, this is some auto-generated code from the designer file.

    /// <summary>
    ///   Looks up a localized string similar to When creating a Commissioning change request, you must select valid Assignees, a Type, a Component, and at least one (1) affected unit..
    /// </summary>
    public static string MyErrorMessage {
        get {
            return ResourceManager.GetString("MyErrorMessage", resourceCulture);
        }
    }
    

    That way, I was able to simply do:

    string message = Errors.MyErrorMessage;
    

    Where Errors is the Errors.resx file created through Visual Studio and MyErrorMessage is the key.

    0 讨论(0)
提交回复
热议问题