read string from .resx file in C#

前端 未结 14 2266
一生所求
一生所求 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:42

    Assuming the .resx file was added using Visual Studio under the project properties, there is an easier and less error prone way to access the string.

    1. Expanding the .resx file in the Solution Explorer should show a .Designer.cs file.
    2. When opened, the .Designer.cs file has a Properties namespace and an internal class. For this example assume the class is named Resources.
    3. Accessing the string is then as easy as:

      var resourceManager = JoshCodes.Core.Testing.Unit.Properties.Resources.ResourceManager;
      var exampleXmlString = resourceManager.GetString("exampleXml");
      
    4. Replace JoshCodes.Core.Testing.Unit with the project's default namespace.

    5. Replace "exampleXml" with the name of your string resource.

提交回复
热议问题