将值分配给另一个位置

时间:2015-04-22 07:55:44

标签: c# asp.net asp.net-mvc

我有一个非常简单的问题。但是麻烦我。

我有以下for循环。我需要指定一些值。

int i;
for (i = currPos + 1; i < expPos;i++ )
{
    [i + 1] = i;// I want to assign i th position to the i+1 
}

1 个答案:

答案 0 :(得分:1)

我相信你想要以下内容:

//You would want to create a custom Player class to store this data as it looks silly here but:
        string[] objectNames = { "player1", "player2", "player3", "player4" };
        int[] objectPositionX = { 5, 10, 15, 20 };
        int[] objectPositionY = { 50, 60, 70, 70 };
        for (int i = 0; i < objectNames.Length; i++)
        {
            //An example of this use would be teleporting a player to another player? Say player 2 to player 4's location.
            if(objectNames[i] == "player2")
            {
                objectPositionX[i] = objectPositionX[3];
                objectPositionY[i] = objectPositionY[3];
            }
        }

        //I'm only taking a stab at what you want as the question was a tad vague. But hope this helps.