通过ResourceManager中的所有资源循环 - C# [英] Loop through all Resources in ResourceManager - C#
问题描述
我如何循环把所有的资源,ResourceManager的?
How do I loop into all the resources in the resourcemanager?
即:
的foreach(在ResourceManager中的字符串资源)
//做一些与林资源。
Ie: foreach (string resource in ResourceManager) //Do something with the recource.
感谢
推荐答案
使用的ResourceManager。<一个href=\"http://msdn.microsoft.com/en-us/library/system.resources.resourcemanager.getresourceset.aspx\">GetResourceSet()对于给定文化的所有资源的列表。返回的ResourceSet实现IEnumerable(您可以使用的foreach)。
Use ResourceManager.GetResourceSet() for a list of all resources for a given culture. The returned ResourceSet implements IEnumerable (you can use foreach).
要回答尼科的问题:您可以通过它转换为普通的的IEnumerable&LT算一个
和使用<$c$c>Enumerable.Count<T>()$c$c>扩展方法,这在C是新的3.5#:的IEnumerable
的元素;对象&gt;
To answer Nico's question: you can count the elements of an IEnumerable
by casting it to the generic IEnumerable<object>
and use the Enumerable.Count<T>()
extension method, which is new in C# 3.5:
using System.Linq;
...
var resourceSet = resourceManager.GetResourceSet(..);
var count = resSet.Cast<object>().Count();
这篇关于通过ResourceManager中的所有资源循环 - C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!