如何使用数组值进行大小写切换(不是数组编号)

Blo*_*ust 7 .net c# arrays switch-statement

你如何使用数组的VALUE而不是数组中用于确定大小写的数字?在我的代码中:

for (int x = 0; x < 3; x++)
        {
            switch (position[x])
            {
                case 0:
                    label1.Text = people[x];
                    break;
                case 1:
                    label2.Text = people[x];
                    break;
                case 2:
                    label3.Text = people[x];
                    break;
            }
        }
Run Code Online (Sandbox Code Playgroud)

当它运行时,它使用位置[]中的x而不是位置[x]的值来确定使用哪种情况.例如,当x为0,但position [x]的值为1时,它使用大小写0.如何获取该值?

编辑:我的代码确实是问题....由于某种原因早上调试有创建虚假图像的效果...:P作为一个FYI,这是正确的代码...

for (int x = 0; x < 3; x++)
        {
            if (position[x] == 2)
            {
                position[x] = 0;
            }

            else
            position[x]++;

        }

        for (int x = 0; x < 3; x++)
        {
            int val = position[x];
            switch (val)
            {
                case 0:
                    label1.Text = people[x];
                    break;
                case 1:
                    label2.Text = people[x];
                    break;
                case 2:
                    label3.Text = people[x];
                    break;
            }
Run Code Online (Sandbox Code Playgroud)

在位置[x]的上部第一个外观中,我只放置了x.感谢您的帮助!

hun*_*ter 4

尝试这个:

    for (int x = 0; x < 3; x++)
    {
        int val = position[x];
        switch (val)
        {
            case 0:
                label1.Text = people[x];
                break;
            case 1:
                label2.Text = people[x];
                break;
            case 2:
                label3.Text = people[x];
                break;
        }
    }
Run Code Online (Sandbox Code Playgroud)

也许更容易说的是:

for(int x = 0; x < 3; x++)
{
    Label label = MyForm.ActiveForm.Controls["label" + position[x]] as Label;
    if (label != null) label.Text = people[x];
}
Run Code Online (Sandbox Code Playgroud)