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: 
Well, both times, you're converting to an array, which might not be so efficient if the IEnumerable is very large (like you said). You could create a generic extension method for IEnumerable, like:

```
public static void ForEach<T>(this IEnumerable<T> current, Action<T> action) {
    foreach (var i in current) {
        action(i);
    }
}

```

and then you could do this:

```
IEnumerable<int> ints = new List<int>();
ints.Where(i => i == 5).ForEach(i => Console.WriteLine(i));

```
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.