Technically, ForEach() is not LINQ-related,
I know.
and on the whole this is
obviously an inferior solution (as there's no need to convert an
IEnumerable to List just to iterate over it).
<<
On account that you don't know me I will ignore the fact that you are
telling me something so obvious
The way I see it, the lack of Enumerable.ForEach() in LINQ is an
indication that the preferred way of doing some action for every
element of an IEnumerable is still the plain foreach statement.
<<
I disagree with this. IEnumerable.ForEach would merely do the same as a
foreach anyway, so there would be absolutely no difference; it's merely a
matter of taste. I think the lack of IEnumerable.ForEach is an annoyance.
names.ForEach(Console.WriteLine);
vs
foreach(string name in names)
Console.WriteLine(name);
It's a minor difference, but why stop me from doing it when they are
equivalent?
LINQ
is really for manupulation on the sequences themselves - filtering,
sorting, grouping, projecting etc - not actions on their individual
elements.
<<
Well, I must say I do agree, but I still think IEnumerable.ForEach would be
nice.
But back onto the original topic. I know that List.ForEach is not LINQ but
I think some people still struggle to differentiate between lamdas and LINQ.
I suspected the original person may have meant this but incorrectly called
it "LINQ". The answer could be right but the question wrong, which is why I
suggested it. I can't think of any way LINQ could be used to improve the
original code, so I thought I'd try to throw some more light on the original
advice instead.