最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

SEO心得admin50浏览0评论
本文介绍了算术运算结果不以标签显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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);

发布评论

评论列表(0)

  1. 暂无评论