gpt4 book ai didi

c# - 文本框值到 int 数组

转载 作者:行者123 更新时间:2023-12-02 05:38:22 27 4
gpt4 key购买 nike

我的表格看起来像这样:

http://content.screencast.com/users/TT13/folders/Jing/media/7689e48c-9bd6-4e22-b610-656b8d5dcaab/2012-07-06_0347.png

x, y, A,B,C 是矩阵。 x 右边的文本框被命名为 x1,...,x6A 右边的文本框被命名为

a11,...,a16
...
a61, ... ,a66

它们都是整数。我想要做的是,将这些值放入数组中,例如:

x=(20,...,756);

然后将 A 放入二维数组,如 a[1][1]=932 ... a[6][6]=666

如果是,怎么办?与组框?我不知道如何解决这个问题。提前致谢

最佳答案

看到您拥有名称嵌入我们可以编写的矩阵位置的控件
这里没有错误检查,我假设数字总是整数......

    int[] xMatrix = new int[6];
int[,] aMatrix = new int[6,6];

foreach (Control control in this.Controls)
{
if (control is TextBox)
{
string pos = control.Name.SubString(1);
if(control.Name.StartsWith("a"))
{
int matrixPos = Convert.ToInt32(pos) ;
int x = (matrixPos / 10) - 1;
int y = (matrixPos % 10) - 1;
aMatrix[x,y] = Convert.ToInt32(control.Text);
}
else if(control.Name.StartsWith("x")
{
int arrayPos = Convert.ToInt32(pos) - 1;
xMatrix[arrayPos] = Convert.ToInt32(control.Text);
}
}
}

关于c# - 文本框值到 int 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11353587/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com