C# foreach 循环项软“中断”

发布于 2024-10-09 15:06:54 字数 324 浏览 0 评论 0原文

假设我有一个 foreach 循环来对 List MyTypeInstanveVariable 执行一些处理,

foreach(MyType item in MyTypeInstanceVariable) {
    if (cond1) {}

    if (cond2) {}
}

如果满足 cond1,我想前进到 MyTypeInstanceVariable 中的下一项。现在我可以添加一点布尔值来检查是否评估 cond2,但是是否有一些内置命令可以快速移动到下一个项目?我不能使用break,因为这会完全脱离foreach循环

谢谢 托马斯

let's say I have a foreach loop to perform some processing on List MyTypeInstanveVariable

foreach(MyType item in MyTypeInstanceVariable) {
    if (cond1) {}

    if (cond2) {}
}

If cond1 is met I want to advance to the next item in the MyTypeInstanceVariable. Now I could add a little boolean to check whether to evaluate cond2, but is there some built in command that will quickly move onto the next item? I can't use break as that would break out of the foreach loop altogether

Thanks
Thomas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝影如岚 2024-10-16 15:06:54

您正在寻找 continue 语句。

You are looking for the continue statement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文