Which way is more effective?
Posted
by Danny Chen
on Stack Overflow
See other posts from Stack Overflow
or by Danny Chen
Published on 2010-05-06T02:49:53Z
Indexed on
2010/05/06
2:58 UTC
Read the original article
Hit count: 379
I have a huge IEnumerable(suppose the name is myItems), which way is more effective?
Solution 1: Filter it first then ForEach.
Array.ForEach(myItems.Where(FILTER-IT-HERE).ToArray(),MY-ACTION);
Solution 2: Do RETURN in MY-ACTION if the item is not up to the mustard.
Array.ForEach(myItems.ToArray(),MY-ACTION-WITH-FILTER);
Is one of them always better than another? Or any other good suggestions? Thanks in advance.
© Stack Overflow or respective owner