Linked Questions
11 questions linked to/from Lambda Expression using Foreach Clause
488
votes
20
answers
217k
views
Why is there no ForEach extension method on IEnumerable?
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 ...
2
votes
5
answers
4k
views
Linq - Is there a IEnumerable.ForEach<T> extension method that I'm missing? [duplicate]
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 ...
1
vote
0
answers
372
views
Why ForEach is List<T> member, but not IEnumerable<T> extention method? [duplicate]
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)...
886
votes
22
answers
733k
views
LINQ equivalent of foreach for IEnumerable<T>
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?
20
votes
8
answers
10k
views
C# foreach vs functional each [closed]
Which one of these do you prefer?
foreach(var zombie in zombies)
{
zombie.ShuffleTowardsSurvivors();
zombie.EatNearbyBrains();
}
or
zombies.Each(zombie => {
zombie....
14
votes
4
answers
7k
views
Existing LINQ extension method similar to Parallel.For? [duplicate]
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 ...
10
votes
6
answers
305
views
Is there a way to set values in LINQ?
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 = "...
0
votes
5
answers
973
views
Replacing a foreach with a linq statement
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 ...
-3
votes
2
answers
2k
views
How can I write foreach loop to sum elements in lamba expression?
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 ...
2
votes
2
answers
342
views
ForEach -- where are you? [duplicate]
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 ...
0
votes
3
answers
173
views
why .net c# lack of "EACH" [duplicate]
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>....