简体   繁体   English

C#+ Inputbox +多维数组

[英]c# + Inputbox + multidimensional array

Im having abit of trouble trying to figure out how to get my VB inputbox to work and then add the value entered into my multidimensional array. 我在尝试弄清楚如何使我的VB输入框工作,然后将输入的值添加到多维数组中时遇到麻烦。

The array looks like this: 该数组如下所示:

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

and so far this is what i have for the inputbox. 到目前为止,这是我对输入框的要求。

 string value;
 int num;

 value = Microsoft.VisualBasic.Interaction.InputBox("Enter Number of Products", "Monday");

I need to have Monday-Friday values for 4 weeks. 我需要有4周的周一至周五的值。 To do this i was thinking of using the inputbox in a for loop perhaps? 为此,我正在考虑在for循环中使用inputbox? Everytime the user enters input for that day it would insert it into the array? 每当用户输入当天的输入内容时,都会将其插入数组吗?

Then repeat that for the 4 weeks? 然后重复4周吗?

Open to any suggestions as i am not sure the best way to go about it. 开放任何建议,因为我不确定最好的解决方法。

Thanks! 谢谢!

Using the inputbox isn't really the best way to accept inputs, as a matter of fact, it's not even good, but to satisfy your needs for now, this should be the shortest route. 实际上,使用输入框并不是接受输入的最佳方法,事实上,它甚至不好,但是要满足您现在的需求,这应该是最短的途径。

VB.NET VB.NET

 Dim toys(4, 3) As String
    For week As Integer = 0 To 3
        For day As Integer = 0 To 4
        toys(day, week) = InputBox("Please enter value for Day " & CStr(day + 1) & " in week " & CStr(week + 1) & ".")
    Next day
 Next week

C# C#

string[,] toys = new string[5, 4];
for (int week = 0; week <= 3; week++) {
    for (int day = 0; day <= 4; day++) {
        toys(day, week) = Interaction.InputBox("Please enter value for Day " + Convert.ToString(day + 1) + " in week " + Convert.ToString(week + 1) + ".");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM