How do I jump out of a foreach loop in C#?

后端 未结 11 2195
醉酒成梦
醉酒成梦 2020-12-13 05:40

How do I break out of a foreach loop in C# if one of the elements meets the requirement?

For example:

foreach(string s in sList){
              


        
11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 06:08

    You can use break which jumps out of the closest enclosing loop, or you can just directly return true

提交回复
热议问题