private void RefreshAllUser(Msg msg)
{
int length = LV_SysUser.Items.Count;
while (length > 0)
{
int i = 0;
String IP = LV_SysUser.Items[i].SubItems[1].Text.ToString();
LV_SysUser.Items[i].SubItems[5].Text = "0";
msg.Msgtype = MsgType.PaperAlive;
SendMsgToOne(IPAddress.Parse(IP), 9601, msg);
length--;
i++;
}
}
各位大神,此方法中的i在while语句内部定义,在while结束之前的i++有用吗?我感觉是没用的,那这样的话永远操作的都是Item[0],写源码的也是大神,应该也不会犯这么低级的错误吧,求指导while
{
int length = LV_SysUser.Items.Count;
while (length > 0)
{
int i = 0;
String IP = LV_SysUser.Items[i].SubItems[1].Text.ToString();
LV_SysUser.Items[i].SubItems[5].Text = "0";
msg.Msgtype = MsgType.PaperAlive;
SendMsgToOne(IPAddress.Parse(IP), 9601, msg);
length--;
i++;
}
}
各位大神,此方法中的i在while语句内部定义,在while结束之前的i++有用吗?我感觉是没用的,那这样的话永远操作的都是Item[0],写源码的也是大神,应该也不会犯这么低级的错误吧,求指导while
没看清楚。 private void RefreshAllUser(Msg msg)
{
int length = LV_SysUser.Items.Count;
while (length > 0)
{
int i = 0;
String IP = LV_SysUser.Items[i].SubItems[1].Text.ToString();
LV_SysUser.Items[i].SubItems[5].Text = "0";
msg.Msgtype = MsgType.PaperAlive;
SendMsgToOne(IPAddress.Parse(IP), 9601, msg);
length--;
i++;
}
}
后面的i++是有用的,但是每次循环都把i赋值成0了啊,int i得定义到外面去。
不是的话再讨论。
private void RefreshAllUser(Msg msg)
{
int length = LV_SysUser.Items.Count; int i = 0; while (length > 0)
{
String IP = LV_SysUser.Items[i].SubItems[1].Text.ToString();
LV_SysUser.Items[i].SubItems[5].Text = "0";
msg.Msgtype = MsgType.PaperAlive;
SendMsgToOne(IPAddress.Parse(IP), 9601, msg);
length--;
i++;
}
}
从你贴出的代来看,确实i一直是0,
同事的代码有问题,要多沟通,才不会出现bug套bug的情况,奇怪的问题最好有KB
估计有这一次错误,LZ以后应该不会在出这样的问题,
这样的错误出一次就能记忆犹新。
乃们不要这样说大神
其实大神只是想show一下初始化
不明白什么思路,是计数器还是控制循环,一定要找到那个人,呵呵~~
没人规定 int i=0 必须放在 while 外面,也没有人规定循环中的数组必须要被遍历,要看作者意图。
int i=0;
while (length > i)
{。。