gpt4 book ai didi

.net - 如何以编程方式枚举 resx 文件中的资源?

转载 作者:行者123 更新时间:2023-12-02 06:23:39 25 4
gpt4 key购买 nike

使用 Visual Studio 2010

如何枚举位于我的程序集中的特定资源文件 (.resx) 中的所有资源?

在我的项目中,我有一个包含 3 个文本文件(字符串资源)的 Resources.resx 文件。我需要枚举这 3 个文件,然后使用它们的名称来获取它们的内容。

谢谢。

最佳答案

使用 ResXResourceReader来自 System.Windows.Forms .

It Enumerates XML resource (.resx) files and streams, and reads the sequential resource name and value pairs


public static void Main()
{

// Create a ResXResourceReader for the file items.resx.
ResXResourceReader rsxr = new ResXResourceReader("items.resx");

// Iterate through the resources and display the contents to the console.
foreach (DictionaryEntry d in rsxr)
{
Console.WriteLine(d.Key.ToString() + ":\t" + d.Value.ToString());
}

//Close the reader.
rsxr.Close();

}

关于.net - 如何以编程方式枚举 resx 文件中的资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4656883/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com