for example
foreach (var item in List<int> a)
{
b.add(item);
c+=item;
dosomething();
}
how to write this into Linq form? or is it necessary?
I guess it has the following format: var b = a.xxxx(x=>(c+=x;dosomething())).ToList()
Since LINQ is really intended to be a query language, I would say it’s bad style to have queries that have secondary effects when they are evaluated. I’d personally either leave things the way they are, or change it to something like this:
Even though you end up iterating over the list multiple times, it’s much easier to glance at each line of code and know immediately what it does.