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

后端 未结 11 2154
醉酒成梦
醉酒成梦 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条回答
  •  伪装坚强ぢ
    2020-12-13 05:47

    how about:

    return(sList.Contains("ok"));
    

    That should do the trick if all you want to do is check for an "ok" and return the answer ...

提交回复
热议问题