它只显示最后一次乘法 [英] its show only last multiplication
本文介绍了它只显示最后一次乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void btngenaratetable_Click(object sender, EventArgs e)
{
int number = Convert.ToInt32(txtinputno.Text);
int limit = Convert.ToInt32(txtlimit.Text);
for (int x = 1; x <= limit; x++)
{
int result = number * x;
string final = number + " * " + x + " = " + result+ "</br>";
lblshowresult.Text = Convert.ToString(final);
}
推荐答案
这里的问题是你要更新你的文本框lblshowresult.Texteveryvery,因为它只显示你的最后的结果。
如果修改代码如下:
issue here is you are updating your textbox lblshowresult.Textevery time because of which it get shows you only the last result.
If you modify the code like:
int number = 3;
int limit = 3;
for (int x = 1; x <= limit; x++)
{
int result = number * x;
string final = number + " * " + x + " = " + result+ "</br>";
//lblshowresult.Text = Convert.ToString(final);
Console.WriteLine(final.ToString());
}
你可以看到所有的结果。为了更好地看到你使用标签而不是文本框。
--SG
you can see all the result. in order to see the complete better you use label instead of textbox.
--SG
因为*的类型是字符串,但你不能直接将int转换为字符串
你必须转换为字符串。
because the type of * is string but you can not convert int to string directly
you must convert to string it .
这篇关于它只显示最后一次乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文