C # has an operator foreach.
As Jon hints (and Eric clearly indicates ), LINQ designers wanted to keep the methods without side effects, while foreachviolating this contract.
In fact, there is a foreachmethod that applies this predicate in classes List<T>and Array, but it was introduced in the .NET Framework 2.0, and LINQ only with 3.5. They are not connected.
, :
public static void ForEach<T> (this IEnumerable<T> enumeration, Action<T> action)
{
foreach (T item in enumeration)
action (item);
}
, , , .
var list = new List<int> {1, 2, 3, 4, 5};
list.Where (n => n > 3)
.ForEach (Console.WriteLine);
, ol foreach .
, void Func<T>, Action<T>.
Func<T> , T Action<T> void, T.