在我的mutlidimensional数组中搜索值 [英] Searching value in my mutlidimensional array
问题描述
我试图找到一种从VisualBasic输入框中获取2个值的方法,然后使用这些值在我的多维数组中查找某个点并将值输出到我的文本框。
这是我提出的代码。
int x = 0 ;
int y = 0 ;
玩具[x,y] = Microsoft.VisualBasic.Interaction.InputBox( 请输入日期的值 + Convert.ToString(x)+ in week +转换.ToString(y)+ 。);
txtOutput.Text + = 当天完成的产品是: +玩具[x,y];
我的问题是用户可能会以字符串格式输入星期几,例如; 星期一然后一天将是一个int。
我的阵列看起来像这样。
http://i.imgur.com /QHy5SYW.jpg
如果有人能就如何让这些代码发挥作用给我一些想法,我将不胜感激。 :)
你可以处理这种情况的一种方法(// 在表单范围
使用 Microsoft.VisualBasic;
public enum WeekDay
{
Monday,星期二,星期三,星期四,星期五
}
public enum 周
{
一,二,三,四
}在方法中:
int x = 0 ;
int y = 0 ;
int 结果;
string intCandidate = Interaction.InputBox( 请输入Day的值 +((WeekDay)x).ToString()+ 在周 +((周)y).ToString());
if ( Int32 .TryParse(intCandidate, out 结果))
{
toys [x,y] = result;
}
其他
{
// < span class =code-comment>处理错误输入
throw new ArgumentException( 您必须输入一个整数。);
}考虑是否还要检查x,y变量以确保它们在适当的范围内。
为什么我使用Enums而不仅仅是List< string>:只是因为我觉得这样做的方式略有不同。
我想知道为什么你需要在这里使用Visual Basic ;为什么不在C#中使用两个NumericUpDown控件?
Im trying to find a way to get 2 values from a VisualBasic inputbox, and then use those values to find the certain spot in my multidimensional array and output the value to my textbox.
This is the code i have come up with.
int x = 0;
int y = 0;
toys[x,y] = Microsoft.VisualBasic.Interaction.InputBox("Please enter value for Day " + Convert.ToString(x) + " in week " + Convert.ToString(y) + ".");
txtOutput.Text += "Products completed on that day are: " + toys[x, y];
My issue is that the user might enter the day of the week in string format eg; "Mon" and then day would be an int.
My array looks like this.
http://i.imgur.com/QHy5SYW.jpg
If anyone could give me some ideas as to how to get this code to work it would be greatly appreciated. :)
One way (among many) you could handle this:// in Form scope using Microsoft.VisualBasic; public enum WeekDay { Monday, Tuesday, Wednesday, Thursday, Friday } public enum Week { One, Two, Three, Four }In a method:
int x = 0; int y = 0; int result; string intCandidate = Interaction.InputBox("Please enter value for Day " + ((WeekDay)x).ToString() + " in Week " + ((Week)y).ToString()); if(Int32.TryParse(intCandidate, out result)) { toys[x, y] = result; } else { // handle error input throw new ArgumentException("You must input an integer."); }Consider whether you should also check the x,y variables to make sure they are in the proper range.
Why did I use Enums rather than just List<string>: just because I felt like doing it a slightly different way.
I wonder why you needed to use Visual Basic here; why not just use two NumericUpDown Controls in C# ?
这篇关于在我的mutlidimensional数组中搜索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!