Question: 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.

Answer: 
Everything else being equal, calling `ToArray()` first will impart a greater performance hit than when calling it last. Although, as has been stated by others before me,

1. Why use `ToArray()` and `Array.ForEach()` at all?
2. We don't know that everything else actually is equal since you do not reveal the implementation details of your filter and action.
**I would say that this falls into the category of premature optimization.** If, after establishing benchmarks, you find that the code is too slow, you can always try each approach and pick the result that works better for you.

Since we don't know how the `IEnumerable<>` is produced it's hard to say which approach will perform better. We also don't know how many items will remain after you apply your predicate - nor do we know whether the action or iteration steps are going to be the dominant factor in the execution of your code. The only way to know for sure is to try it both ways, profile the results, and pick the best.

Performance aside, I would choose the version that is most clear - which (for me) is to first filter and then apply the projection to the result.