C # - difference between "foreach" and extension method: ForEach

Can someone point out the differences between the operators C#and their similar extension methods? for example: foreachcompared to .ForEach(extension method).

If there is any difference , what are they? Security? Efficiency? Which one is better to use? Which one is safer? and etc.

And if there are no differences, then why write them?

I thought and looked for this question a little, if mine did not find an answer. thanks in advanced condition.

+4
source share
2 answers

. .ForEach.

/ . "" , .ForEach foreach, . , , , (: ). , , , . , , , - .

, .ForEach , - , "" . foreach .

, : ForEach IEnumerable?

. , , , . , .

, . :

foreach (Foo foo in foos) { foo; }

:

foos.ForEach((Foo foo) = > {, foo;});

. , , .

+4

.ForEach Parallel.ForEach. .ForEach / . , , .

, Parallel.ForEach, foreach .

0

All Articles