同时使用两个“For”

时间:2014-04-26 03:20:01

标签: c# for-loop

好吧,我试图使用两个命令" For"在同一时间。

代码:

public static void SendToMap(string map, string packet)
{
    for (int i = 0; i < Clients.Count; i++)
        for (int i2 = 0; i2 < Globals.Player_HighIndex; i2++)
        {
            Console.Write(i);
            Console.Write(i2);
            if (PStruct.character[i2, PStruct.player[i2].SelectedChar].Map == map)
            {
                if (Listen.Clients[i].Index == i2)
                {
                    Clients[Listen.Clients[i].ListIndex].TCPClient.Client.SendBufferSize = Encoding.UTF8.GetByteCount(packet);
                    Clients[Listen.Clients[i].ListIndex].TCPClient.Client.Send(Encoding.UTF8.GetBytes(packet));
                }
            }
        }
}

Globals.Player_HighIndex值为1,Clients.Count为0,即我希望命令执行如下:

(0,0) (0,1)

做了什么:

(0,0)

任何人都有提示或解决方案吗?

1 个答案:

答案 0 :(得分:1)

你太早结束你的循环。你需要&lt; =。

for (int i2 = 0; i2 <= Globals.Player_HighIndex; i2++)