How do i exit a List.ForEach loop when using an anonymous delegate?

As others have posted, you can’t exit the loop in ForEach.

Are you able to use LINQ? If so, you could easily combine TakeWhile and a custom ForEach extension method (which just about every project seems to have these days).

In your example, however, List<T>.FindIndex would be the best alternative – but if you’re not actually doing that, please post an example of what you really want to do.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)