我一直在C#中徘徊,我目前做得很好,但我試圖找出如何在多維數組中搜索索引。我有一個陣列,用於每天製作的產品。這通過詢問用戶輸入(使用輸入框)例如顯示每週製作的產品。第1周星期一= 10熊,星期三= 20熊。第2周星期二= 30,星期五= 11等。我知道IndexOf,但是這是爲了找到給定值的索引。我想搜索索引並查找並顯示值。C#如何搜索數組中的索引以找到值
的代碼如下:
class Day
{
private string monday;
private string tuesday;
private string wednesday;
private string thursday;
private string friday;
public string Monday
{
get { return monday; }
set { monday = value; }
}
public string Tuesday
{
get { return tuesday; }
set { tuesday = value; }
}
public string Wednesday
{
get { return wednesday; }
set { wednesday = value; }
}
public string Thursday
{
get { return thursday; }
set { thursday = value; }
}
public string Friday
{
get { return friday; }
set { friday = value; }
}
}
private void btnSelect_Click(object sender, EventArgs e)
{
Day[] week = new Day[4];
//Week[0] = new Day(); Ask users for input box value
E.g.Monday = Microsoft.VisualBasic.Interaction.InputBox("Enter the amount of products made on Monday for week 1", "Product Amount"),etc
//Prints the amounts
txtOutput.Text += "The product allocation is as follows:" + "\r\n" + "\r\n";
txtOutput.Text += " Mon Tue Wed Thu Fri \r\n";
int weeknum = 0;
//Iterates through and shows the values for each day of the week.
foreach (Day days in week)
{
weeknum++;
if (days != null)
{
txtOutput.Text += "Week " + weeknum + " " + days.Monday + " " + days.Tuesday + " " + days.Wednesday + " " + days.Thursday + " " + days.Friday + "\r\n";
}
}
}
我不明白你的問題。 (找到索引?),你也沒有任何多維數組。 –