call a function for each value in a generic c# collection [duplicate]

LINQ doesn’t help here, but you can use List<T>.ForEach:

List<T>.ForEach Method

Performs the specified action on each element of the List.

Example:

myList.ForEach(p => myFunc(p));

The value passed to the lambda expression is the list item, so in this example p is a long if myList is a List<long>.

Leave a Comment