Sometimes it would be useful to have ForEach extension on IEnumerable, so we do not need to write foreach.
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
The LINQ does not have this extension, because LINQ extensions are supposed to be side-effect free (they do not change IEnumerable data) and ForEach is meant to change those data.
Sometimes it would be useful to have
ForEach
extension onIEnumerable
, so we do not need to writeforeach
.The LINQ does not have this extension, because LINQ extensions are supposed to be side-effect free (they do not change
IEnumerable
data) and ForEach is meant to change those data.