C#做一个计算器出现了字符串输入的格式不正确,求解答~附代码~~~

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da... using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace 计算器{ public partial class 计算器 : Form { string x; public 计算器() { InitializeComponent(); } private void button4_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { Double num1 = Convert.ToDouble(this.textBox1.ToString()); Double num2 = Convert.ToDouble(this.textBox2.ToString()); string ch = x; String Result = ""; switch (ch) { case "+": Result = (num1 + num2).ToString(); this.textBox3.Text = Result; break; case "-": Result = (num1 - num2).ToString(); this.textBox3.Text = Result; break; case "*": Result = (num1 * num2).ToString(); this.textBox3.Text = Result; break; case "/": Result = (num1 / num2).ToString(); this.textBox3.Text = Result; break; default: break; } } private void button2_Click(object sender, EventArgs e) { Application.Exit(); } private void 计算器_Load(object sender, EventArgs e) { } private void label3_Click(object sender, EventArgs e) { } private void radioButton3_CheckedChanged(object sender, EventArgs e) { x = "+"; } private void button3_Click(object sender, EventArgs e) { this.textBox1.Clear(); this.textBox2.Clear(); this.textBox3.Clear(); } private void textBox3_TextChanged(object sender, EventArgs e) { } private void textBox1_TextChanged(object sender, EventArgs e) { } private void radioButton2_CheckedChanged(object sender, EventArgs e) { x = "-"; } private void radioButton1_CheckedChanged(object sender, EventArgs e) { x = "*"; } private void radioButton4_CheckedChanged(object sender, EventArgs e) { x = "/"; } }} 展开
 我来答
匿名用户
2017-10-22
展开全部
转成int类型就好,double没必要,而且,报错的地方你写成textbox直接转换了,要.一下出来text属性,这个属性才是你输入的字符的值,而这个属性本来就是string的,无需tostring()
wjshan0808
2017-10-22 · TA获得超过601个赞
知道小有建树答主
回答量:696
采纳率:74%
帮助的人:378万
展开全部
取textBox1.Text.ToString(); textBox2也一样。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式