如何在多维数组的特定索引中查找值

时间:2016-01-05 05:13:01

标签: c# multidimensional-array input indexof

我有一个多维数组,代表一周中的星期几(星期一,星期二等)和一个月的星期(第1周等),它显示了每天产品的数量。该数组正由用户输入(输入框)填充,我试图找出一种提示用户一周的方法:第1周等和一天。我知道IndexOf,但这给了我索引而不是索引中的值。

我的代码是:

int[,] week = new int[4, 5];

for (int Row = 0; Row < week.GetLength(0); Row++)
                {
                    if (Row == 0)
                    {
                        Week = "Week 1  ";
                    }
                    else if (Row == 1)
                    {
                        Week = "Week 2  ";
                    }
                    else if (Row == 2)
                    {
                        Week = "Week 3  ";
                    }
                    else if (Row == 3)
                    {
                        Week = "Week 4  ";
                    }
                    txtOutput.Text += "\r\n" + Week + ": ";
                    for (int Col = 0; Col < week.GetLength(1); Col++)
                    {
                        if (Col == 0)
                        {
                            Day = "Monday";
                        }
                        else if (Col == 1)
                        {
                            Day = "Tuesday";
                        }
                        else if (Col == 2)
                        {
                            Day = "Wednesday";
                        }
                        else if (Col == 3)
                        {
                            Day = "Thursday";
                        }
                        else if (Col == 4)
                        {
                            Day = "Friday";
                        }

                        string value = Microsoft.VisualBasic.Interaction.InputBox("Enter the amount of products made on " + Day + " for " + Week, "Product Amount");

                        week[Row, Col] = Int32.Parse(value);
                        txtOutput.Text += " ";
                        txtOutput.Text += value + "         ";

                    }
                }

我可能不得不为此制作一些自定义方法,因为我没有内置的方法,但我无法弄清楚它会是什么样子。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

周[Row,Col]就是答案。 例如周[0,3],周[2,4] ...