There is no ForEach extension for IEnumerable
;
(没有IEnumerable
ForEach扩展;)
only for List<T>
. (仅用于List<T>
。)
So you could do (所以你可以做)
items.ToList().ForEach(i => i.DoStuff());
Alternatively, write your own ForEach extension method:
(或者,编写您自己的ForEach扩展方法:)
public static void ForEach<T>(this IEnumerable<T> enumeration, Action<T> action)
{
foreach(T item in enumeration)
{
action(item);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…