首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

读取资源文件中全部key和value

2013-02-28 
读取资源文件中所有key和value在项目中的Resources目录下有个A.Resx资源文件,文件里面有内容如下a11a22现

读取资源文件中所有key和value
在项目中的Resources目录下有个A.Resx资源文件,文件里面有内容如下
a1     1
a2     2
现在想一次性读取所有key和value生成一个列表,如list,而不是通过具体的key一个一个的去找value
谢谢。在线等
[解决办法]

public static void Main() 
    {
        // Create a ResourceReader for the file items.resources.
        ResourceReader rr = new ResourceReader("items.resources"); 

        
        // Create an IDictionaryEnumerator to iterate through the resources.
        IDictionaryEnumerator id = rr.GetEnumerator(); 

        // Iterate through the resources and display the contents to the console. 
        while(id.MoveNext())
          Console.WriteLine("\n[{0}] \t{1}", id.Key, id.Value); 

        rr.Close();     
 
    }

[解决办法]
http://msdn.microsoft.com/zh-cn/library/system.resources.resxresourcereader.aspx

热点排行