求助,Winform Dictionary数组移除键值问题.

鬼五拾柒 2015-11-19 02:12:01

Console.WriteLine(ip_client + "管理器进入!");
string[] id = rs.Split(',');
for (int i = 1; i < id.Length; i++)
{
string source = id[i];
if (source != null && connect_client.Keys.Contains(source))
{
strSQL = "update jz_line set work_status='N' where source_id='" + source.Trim() + "'";
if (SQLHelper.Update(strSQL, null))
{
Console.WriteLine(connect_client[source].RemoteEndPoint.ToString() + "client exit.");
Console.WriteLine("-----------------当前已经连接的-----------------");
foreach (var item in connect_client)
{
Console.WriteLine(item.Key + "+" + item.Value);
}
Console.WriteLine("------------------------------------------------");
foreach (var item in connect_client)
{
if (item.Key.Trim() == source)
{
Console.WriteLine("移除");
client_tab.Remove(item.Key);
}
}
Console.WriteLine("-----------------当前已经连接的-----------------");
foreach (var item in connect_client)
{
Console.WriteLine(item.Key + "+" + item.Value);
}
Console.WriteLine("------------------------------------------------");
connect_client[source].Close();

}
}
}

在这段代码里面Dictionary.Remove并没有移除,依然能遍历出来 不知道是啥问题.
...全文
71 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
鬼五拾柒 2015-11-19
  • 打赏
  • 举报
回复
引用 1 楼 xdashewan 的回复:
你遍历的是connect_client,移除的是client_tab
眼瞎了
xdashewan 2015-11-19
  • 打赏
  • 举报
回复
你遍历的是connect_client,移除的是client_tab

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧