这是我的代码:
var assem = Assembly.GetExecutingAssembly();
var fs = assem.GetManifestResourceStream("res.resources");
var rr = new ResourceReader(fs);`
IDictionaryEnumerator dict = rr.GetEnumerator();
谢谢你的帮助
这是我的代码:
var assem = Assembly.GetExecutingAssembly();
var fs = assem.GetManifestResourceStream("res.resources");
var rr = new ResourceReader(fs);`
IDictionaryEnumerator dict = rr.GetEnumerator();
谢谢你的帮助
您可以使用 LINQ 将您提供的数据转换为ResourceReader
可能更易于使用的字典:
using System.Linq;
using System.Collections.Generic;
var assem = Assembly.GetExecutingAssembly();
var fs = assem.GetManifestResourceStream("res.resources");
var rr = new ResourceReader(fs);
Dictionary<string, object> data = rr
.OfType<DictionaryEntry>()
.Select(i => new { Key = i.Key.ToString(), value = i.Value })
.ToDictionary(i => i.Key, i => i.value);
// Getting all resource names
IEnumerable<string> names = data.Keys;
// Getting all values
IEnumerable<object> values = data.Values;
改编自MSDN 文档:
var assem = Assembly.GetExecutingAssembly();
var fs = assem.GetManifestResourceStream("res.resources");
var rr = new ResourceReader(fs);`
IDictionaryEnumerator dict = rr.GetEnumerator();
while (dict.MoveNext())
Console.WriteLine(" {0}: '{1}' (Type {2})",
dict.Key, dict.Value, dict.Value.GetType().Name);
rr.Close();
如果您想要程序集中所有资源的列表,请使用以下内容
var assem = Assembly.GetExecutingAssembly();
var resources = assem.GetManifestResourceNames();