0

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>.Select().Where().First().Any()

Why don't we have

IEnumberable<T>.Each(Action<T> action)?

So instead of 2 lines: Foreach(T t in list) action(t);

we can just call list.Each((t)=>{blah;blah;})?

Is there a concern for performance?

3

3 Answers 3

2

Frequently asked, definitively answered:

http://blogs.msdn.com/b/ericlippert/archive/2009/05/18/foreach-vs-foreach.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

+1 I always wondered about that myself... thanks for the interesting link!
1

List.ForEach

Comments

0

It was made this way, since none of the extention methods on IEnumerable was supposed to have any side effects, and a ForEach would have side effects as it's primary objective.

It was deemed that a foreach loop is not much more verbose to write out.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.