Linked Questions

488 votes
20 answers
217k views

Inspired by another question asking about the missing Zip function: Why is there no ForEach extension method on the IEnumerable interface? Or anywhere? The only class that gets a ForEach method is ...
Cameron MacFarland's user avatar
2 votes
5 answers
4k views

Possible Duplicates: Lambda Expression using Foreach Clause… Why is there not a ForEach extension method on the IEnumerable interface? This seems pretty basic. I'm trying to iterate over ...
Micah's user avatar
  • 117k
1 vote
0 answers
372 views

For example, i have array of int and i need increase each element by 2. In modern c# with linq and extension methods the obvious solution is: var array = new[] {1, 2, 3}; array.ForEach(p => p += 2)...
Sergey Shulik's user avatar
886 votes
22 answers
733k views

I'd like to do the equivalent of the following in LINQ, but I can't figure out how: IEnumerable<Item> items = GetItems(); items.ForEach(i => i.DoStuff()); What is the real syntax?
tags2k's user avatar
  • 84.7k
20 votes
8 answers
10k views

Which one of these do you prefer? foreach(var zombie in zombies) { zombie.ShuffleTowardsSurvivors(); zombie.EatNearbyBrains(); } or zombies.Each(zombie => { zombie....
whatupdave's user avatar
  • 3,402
14 votes
4 answers
7k views

Possible Duplicate: LINQ equivalent of foreach for IEnumerable<T> The linq extension methods for ienumerable are very handy ... but not that useful if all you want to do is apply some ...
Joel Martinez's user avatar
10 votes
6 answers
305 views

Is there a better way to do these assignments with LINQ? IEnumerable<SideBarUnit> sulist1 = newlist.Where(c => c.StatusID == EmergencyCV.ID); foreach (SideBarUnit su in sulist1) su.color = "...
patrick's user avatar
  • 17.1k
0 votes
5 answers
973 views

I am trying to convert this code to linq: foreach (var printer in printers) { if (printer.Installed) installedPrinters.Add(printer); } I am new to Linq and would appreciate pointers on ...
Mike's user avatar
  • 11
-3 votes
2 answers
2k views

How can I write foreach loop shown below as a labmda expression? var sum = 0; foreach (SomeClass obj in SomeListOfClass) { sum += obj.SomeValue; } I am expecting a lambda expression that look like ...
talaa123's user avatar
  • 123
2 votes
2 answers
342 views

Possible Duplicate: Why is there not a ForEach extension method on the IEnumerable interface? I love the .ForEach method on List<T> in C#. How is this not one of the suite of Extension ...
Glenn Ferrie's user avatar
  • 10.4k
0 votes
3 answers
173 views

Possible Duplicate: is there a .Each() (or .ForEach() ) iterator in the .Net standard library? Maybe I am wrong, but I don't see the "EACH" function in .net (3.0)? We can IEnumerable<T>....
GaryX's user avatar
  • 737