Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在整数数组中上下移动_C# - Fatal编程技术网

C# 如何在整数数组中上下移动

C# 如何在整数数组中上下移动,c#,C#,我有以下数组: int[] month = new int[12] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; 这代表我一年中的几个月 现在我有两个按钮和一个标签。标签应仅显示数组中当前项的值。当我按下“下一步”按钮时,它应该在数组中从例如5移动到6,现在在标签中显示6。尝试下面的代码,它将帮助您 将此数组设置为全局数组 加载事件 下一步按钮单击 上一个按钮单击 所以你的问题是什么?你试过什么?我认为你提供的信息不够。这是winforms还是wpf?当

我有以下数组:

int[] month = new int[12] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
这代表我一年中的几个月


现在我有两个按钮和一个标签。标签应仅显示数组中当前项的值。当我按下“下一步”按钮时,它应该在数组中从例如5移动到6,现在在标签中显示6。

尝试下面的代码,它将帮助您

将此数组设置为全局数组

加载事件

下一步按钮单击

上一个按钮单击


所以你的问题是什么?你试过什么?我认为你提供的信息不够。这是winforms还是wpf?当前如何在标签中显示值?我只想在数组中上下移动。我可以用Java执行这项操作,但不能用c。@Bebbie7为什么不能?如果我没记错的话,C做这件事的功能和java做这件事的功能几乎是一样的,那么到底是什么问题呢?第[5]个月。ToString将为您带来6…..是的,这就是我一直在寻找的逻辑,谢谢!
int[] month = new int[12] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
label1.Text = month[4].ToString();
        int ind = Array.IndexOf<int>(month, Convert.ToInt32(label1.Text));
        if ((ind + 1) != 12)
            label1.Text = month[ind + 1].ToString();
        else
            MessageBox.Show("End of the Array element");
            int ind = Array.IndexOf<int>(month, Convert.ToInt32(label1.Text));
            if ((ind - 1) != -1)
                label1.Text = month[ind - 1].ToString();
            else
                MessageBox.Show("End of the Array element");