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

前端 未结 12 922
自闭症患者
自闭症患者 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 15:16

    The ForEach method is not mean to do this. If you want to know if a collection contains an item you should use the Contains method. And if you want to perform a check on all items in a collection you should try the Any extention method.

提交回复
热议问题