gpt4 book ai didi

c# - 如何在给定状态下停止 foreach 循环

转载 作者:太空宇宙 更新时间:2023-11-03 17:55:09 24 4
gpt4 key购买 nike

foreach (String host   in hostArray)
{
string s1 = hostArray[t];
string s2 = branchArray[t];
string con_msg;
t=t+1;
TcpClient socketForServer;
try
{
socketForServer = new TcpClient(s1, 10);
con_msg="Connected";
}
catch
{
ListViewItem item = new ListViewItem();
item.BackColor = Color.LightGreen;
item.Text = (s2);
item.SubItems.Add(s1);
item.SubItems.Add("Not found");
listView1.Items.Add(item);
con_msg = "Not connected";
// I want to exit this round in here and and start next round how to do it
}

NetworkStream networkStream = socketForServer.GetStream();
System.IO.StreamReader streamReader = new System.IO.StreamReader(networkStream);
System.IO.StreamWriter streamWriter =new System.IO.StreamWriter(networkStream);
//code
}

我想退出当前回合并开始下一轮。怎么做。我不想退出 foreach 循环,我只想退出当前回合并开始下一轮

最佳答案

使用 continue 来做到这一点。参见 Documentation

关于c# - 如何在给定状态下停止 foreach 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13005684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com