要求每个值的函数在一个通用的C#集合 [英] call a function for each value in a generic c# collection
问题描述
我有整数值的集合中List集合。
我要调用一个函数的集合,其中函数的参数之一,是一家集值中的每个值。
没有在foreach循环中这样做......有没有办法用一个lambda / LINQ表达式来完成呢?
I have a collection of integer values in a List collection. I want to call a function for each value in the collection where one of the function's argument is a collection value. Without doing this in a foreach loop... is there a way to accomplish this with a lambda/linq expression?
类似... myList.Where(p => myFunc的(p.Value));
感谢,
-s
thanks in advance, -s
推荐答案
LINQ没有帮助在这里,但你可以使用的 列表< T> .ForEach
:
LINQ doesn't help here, but you can use List<T>.ForEach
:
列表< T> .ForEach方法的
执行列表中的每个元素指定的动作
Performs the specified action on each element of the List.
例如:
myList.ForEach(p => myFunc(p));
传递给lambda表达式的值是列表项,所以在这个例子中 p
是长
如果 myList中
是列表<长方式>
这篇关于要求每个值的函数在一个通用的C#集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!