如何在二维数组中存储文本框值 [英] How to store a textbox value in two dimensional array

查看:83
本文介绍了如何在二维数组中存储文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,它接受两个数字,并用逗号分隔.例如:"05,2004".
我有一个二维数组,称为整数类型的store [i] [j].
我想在ith位置存储10,在jth位置存储2010.
这样,store [0] [0]应该等于"05,2010"
到目前为止,我只是在学习和处理一维数组,
并且一直在使用以下语句从文本框中读取值.


I have a text box that takes two numbers separated by a comma. For eg: "05, 2004".
I have a two dimensional array called store[i][j] of integer type.
I would like to store 10 in ith position and 2010 in jth position.
such that, store[0][0] should be equal to "05, 2010"
So far, I''ve only been learning and dealing with one dimensionl array,
and have been using the following statement to read values from a textbox.


if (!int.TryParse(carmake.Text, out store[0]))
MessageBox.Show("type an integer ");


任何帮助将非常感激.谢谢


Any help would be much appreciated. Thanks

推荐答案


可能会对您有所帮助,或者您会有所了解

Hi,
May be this will help you or you''ll get some idea

string textBox = "45,78";
int[,] values = new int[1,2];
string[] textBoxSplit = textBox.Split(',');
values[0, 0] = Convert.ToInt32(textBoxSplit[0]);
values[0, 1] = Convert.ToInt32(textBoxSplit[1]);


二维数组用于构造矩阵.而且,在阵列中的示教点上,您仍然只能保存一项.示例:

[0] [0]:"2010年5月" | [0] [1]:"2010年6月"
[1] [0]:"5,2011" | [1] [1]:"2011年6月"

我认为您需要查看的是List<KeyValuePair<int, int>>Tuple<int, int>.
Two dimensional arrays are used to construct matrices. And at teach point in the array, you could still only save one item. Example:

[0][0] : "5, 2010" | [0][1] : "6, 2010"
[1][0] : "5, 2011" | [1][1] : "6, 2011"

What I think you would need to look at is either List<KeyValuePair<int, int>> or Tuple<int, int>.


这篇关于如何在二维数组中存储文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆