Is there any performance difference between these two statements?
IEnumerable<T>.ToList().ForEach(x => Console.WriteLine(x));
and
foreach (var obj in IEnumerable<T>)
Console.WriteLine(obj)
Is there any performance difference between these two statements?
IEnumerable<T>.ToList().ForEach(x => Console.WriteLine(x));
and
foreach (var obj in IEnumerable<T>)
Console.WriteLine(obj)
In the first example, you will
Console.WriteLine
for each element.In the second example, you will
Console.WriteLine
for each element.There are two performance penalities to the first over the second:
List
object