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

前端 未结 12 933
自闭症患者
自闭症患者 2020-12-14 14:24

In a normal loop you can break out of a loop using break. Can the same be done using an anonymous delegate?

Example inputString and result are both declared outside

12条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 14:56

    If you want a loop, use a loop.

    Action allows for no return value, so there's no way the ForEach function could possibly know that you want to break, short of throwing an exception. Using an exception here is overkill.

提交回复
热议问题