c# - When would I use List<T>.ForEach over a native foreach loop? -
Do the advantages of either approach? If I need to find inventory items and take action on every one, should I use the traditional foreground loop mechanism or go to the list?
Matthew Podovsokie @ Codebetter. Has written an interesting article about this. It was thinking of a problem I was trying to solve a loop. In this article, Matthew argues that with clear loop structures you can think of 'how' rather than 'what'
What are some good reasons to use one over each other? >
For one thing, if you had passed the representative to apply for any reason, you would use it for example, you can make your own list, it can populate etc. And then can apply the representative to each entry. At that point, writing:
list. Foreike (action);
is more simple than foreach (item items in the list) {action (item); }
Comments
Post a Comment