简体   繁体   English

同时使用两个“ For”

[英]Using Two “For” at the same time

Well, I'm trying to use two commands "For" at the same time. 好吧,我试图同时使用两个命令“ For”。

The code: 编码:

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));
                }
            }
        }
}

The Globals.Player_HighIndex value is 1, and Clients.Count is 0, ie, I want the command to be executed as follows: Globals.Player_HighIndex的值为1,Clients.Count为0,即我希望该命令执行如下:

(0,0) (0,1)

What is done: 完成了什么:

(0,0)

Anyone have tips or a resolution? 任何人都有提示或解决方法?

You end your loop too early. 您过早结束循环。 you need <=. 您需要<=。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM