假设我想迭代一个string[][]
,使用匿名类型附加值并在结果上执行通用的ForEach-Extensionmethod(很好的例子,我知道,但我想你会明白要点!)。
这是我的代码:
//attrs = some string[][]
attrs.Select(item => new { name = HttpContext.GetGlobalResourceObject("Global", item[0].Remove(0, 7)), value = item[1] })
.ForEach</*????*/>(/*do stuff*/);
在ForEach的类型参数中我应该放什么?
这是ForEach的样子:
public static void ForEach<T>(this IEnumerable<T> collection, Action<T> act)
{
IEnumerator<T> enumerator = collection.GetEnumerator();
while (enumerator.MoveNext())
act(enumerator.Current);
}
x
就是那个匿名类型。 - Daniel Hilgarth