[英]2 dimensional random values array with 2 user entered values from asp.net web form textboxes
You will print the entire matrix on screen in 10 rows by 10 cols using a function.您将使用函数以 10 行 x 10 列的形式在屏幕上打印整个矩阵。
There will be one more button called transpose.还会有一个称为转置的按钮。 When user clicks on this button, entire matrix will be transposed.
当用户点击这个按钮时,整个矩阵将被转置。 ie the all the data elements in rows will be interchanged with columns.
即行中的所有数据元素将与列互换。 After transpose, it will get printed below again.
转置后,它将再次打印在下面。 Both print should be visible to users.
用户应该可以看到两个打印件。
public void Button1_Click(object sender, EventArgs e)
{
int intLL = Convert.ToInt32(TextBox1.Text);
int intUL = Convert.ToInt32(TextBox2.Text);
int[,] arr = new int[size, size];
for (int row =0; row < size;row++)
{
for(int col=0;col<size;col++)
{
arr[row, col] = r.Next(intLL,intUL);
//Response.Output.Write(arr[row,col]+TextBox1.Text+TextBox2.Text+" ");
Response.Output.Write(arr[row, col] + " ");
}
Response.Write(" </br>");
}
}
public void Button2_Click(object sender, EventArgs e)
{
}
i get the answer how to generate matrix with random values but on button_2 click event how i get transpose of matrix to display it on same screen我得到了如何用随机值生成矩阵的答案,但是在 button_2 单击事件上我如何得到矩阵的转置以在同一屏幕上显示它
Actually you are hardcoding the minimun and maximun values of your Random.Next call.实际上,您正在硬编码Random.Next调用的最小值和最大值。
Just check what the user entered in the textboxes and use that values instead.只需检查用户在文本框中输入的内容并改用该值即可。 After doing that you could do your traspoosing logic.
这样做之后,你可以做你的 traspoosing 逻辑。
Something similar to:类似于:
int minValue = 0;
int maxValue = 0;
if (!Int.TryParse(tbMinimunValue, out minValue) || !Int.TryParse(tbMaximunValue, out maxValue))
{
Response.Write("Please enter numbers");
return;
}
// TODO: Add aditional checks like checking min < max, and min and max are positive values
Random r = new Random();
int size = 10;
int[,] arr = new int[size, size];
for (int i = 0; i < size;i++)
{
for(int j=0;j<size;j++)
{
arr[i, j] = r.Next(minValue, maxValue);
Response.Output.Write(arr[i,j]+" ");
}
Response.Write(" </br>");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.