算术运算结果不以标签显示

编程入门 行业动态 更新时间:2024-10-09 11:16:40
本文介绍了算术运算结果不以标签显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

protected void RadioButton2_CheckedChanged(对象发​​件人,EventArgs e) { int no1,no2; float ans; no1 = Convert.ToInt32( textbox2.Text); no2 = Convert.ToInt32( textbox3.Text); ans = no1 - no2; Label2.Text = ans.ToString(); } 受保护 void RadioButton1_CheckedChanged( object sender,EventArgs e) { int no1,no2; float ans; no1 = Convert.ToInt32( textbox2.Text); no2 = Convert.ToInt32( textbox3.Text); ans = no1 + no2; Label2.Text = ans.ToString(); } 受保护 void RadioButton3_CheckedChanged( object sender,EventArgs e) { int no1,no2; float ans; no1 = Convert.ToInt32( textbox2.Text); no2 = Convert.ToInt32( textbox3.Text); ans = no1 * no2; Label2.Text = ans.ToString(); } 受保护 void RadioButton4_CheckedChanged( object sender,EventArgs e) { int no1,no2; float ans; no1 = Convert.ToInt16( textbox2.Text); no2 = Convert.ToInt16( textbox3.Text); ans = no1 / no2; Label2.Text = ans.ToString(); }

解决方案

我不知道为什么,但你试图将文本textbox1.Text转换为一个整数,而不是文本框中的值:

protected void RadioButton2_CheckedChanged( object sender,EventArgs e) { int no1,no2; float ans; no1 = Convert.ToInt32(textbox2.Text); // 这就是问题所在的问题 no2 = Convert.ToInt32(textbox3.Text ); // 所有带引号的线 ans = no1 - no2; Label2.Text = ans.ToString(); } 受保护 void RadioButton1_CheckedChanged( object sender,EventArgs e) { int no1,no2; float ans; no1 = Convert.ToInt32(textbox2.Text); no2 = Convert.ToInt32(textbox3.Text); ans = no1 + no2; Label2.Text = ans.ToString(); } 受保护 void RadioButton3_CheckedChanged( object sender,EventArgs e) { int no1,no2; float ans; no1 = Convert.ToInt32(textbox2.Text); no2 = Convert.ToInt32(textbox3.Text); ans = no1 * no2; Label2.Text = ans.ToString(); } 受保护 void RadioButton4_CheckedChanged( object sender,EventArgs e) { int no1,no2; float ans; no1 = Convert.ToInt16(textbox2.Text); no2 = Convert.ToInt16(textbox3.Text); ans = no1 / no2; Label2.Text = ans.ToString(); }

在进行转换时取消引号;) 替换它

Convert.ToInt32( textbox2.Text );

有了这个

Convert.ToInt32(textbox2.Text);

protected void RadioButton2_CheckedChanged(object sender, EventArgs e) { int no1, no2; float ans; no1 = Convert.ToInt32("textbox2.Text"); no2 = Convert.ToInt32("textbox3.Text"); ans = no1 - no2; Label2.Text = ans.ToString(); } protected void RadioButton1_CheckedChanged(object sender, EventArgs e) { int no1, no2; float ans; no1 = Convert.ToInt32("textbox2.Text"); no2 = Convert.ToInt32("textbox3.Text"); ans = no1 + no2; Label2.Text = ans.ToString(); } protected void RadioButton3_CheckedChanged(object sender, EventArgs e) { int no1, no2; float ans; no1 = Convert.ToInt32("textbox2.Text"); no2 = Convert.ToInt32("textbox3.Text"); ans = no1 * no2; Label2.Text = ans.ToString(); } protected void RadioButton4_CheckedChanged(object sender, EventArgs e) { int no1, no2; float ans; no1 = Convert.ToInt16("textbox2.Text"); no2 = Convert.ToInt16("textbox3.Text"); ans = no1 /no2; Label2.Text =ans.ToString(); }

解决方案

I don't know why, but you are trying to convert the text "textbox1.Text" to an integer, not the value in the textbox:

protected void RadioButton2_CheckedChanged(object sender, EventArgs e) { int no1, no2; float ans; no1 = Convert.ToInt32(textbox2.Text); //THIS IS WHERE THE PROBLEM WAS ON no2 = Convert.ToInt32(textbox3.Text); //ALL THESE LINES WITH QUOTES ans = no1 - no2; Label2.Text = ans.ToString(); } protected void RadioButton1_CheckedChanged(object sender, EventArgs e) { int no1, no2; float ans; no1 = Convert.ToInt32(textbox2.Text); no2 = Convert.ToInt32(textbox3.Text); ans = no1 + no2; Label2.Text = ans.ToString(); } protected void RadioButton3_CheckedChanged(object sender, EventArgs e) { int no1, no2; float ans; no1 = Convert.ToInt32(textbox2.Text); no2 = Convert.ToInt32(textbox3.Text); ans = no1 * no2; Label2.Text = ans.ToString(); } protected void RadioButton4_CheckedChanged(object sender, EventArgs e) { int no1, no2; float ans; no1 = Convert.ToInt16(textbox2.Text); no2 = Convert.ToInt16(textbox3.Text); ans = no1 /no2; Label2.Text =ans.ToString(); }

Suppress the quotes when you're doing conversions ;) Replace this

Convert.ToInt32("textbox2.Text");

With that

Convert.ToInt32(textbox2.Text);

更多推荐

算术运算结果不以标签显示

本文发布于:2023-11-30 15:47:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650567.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算术   不以   标签

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!