[英]{“Input string was not in a correct format.”}
I cannot figure out wh i am getting error 我无法弄清楚我出错了
"{"Input string was not in a correct format."}" “ {”输入字符串的格式不正确。“}”
When I type for example 5+5 into my Sum Textbox and click equals which should then display my answer in my answer textbox, however when I type 5+5 I get the error show above and I cant seem to fix it. 当我在“求和”文本框中输入例如5 + 5并单击equals时,应该在我的答案文本框中显示我的答案,但是,当我输入5 + 5时,出现上面的错误,我似乎无法解决。
Here is my addition button code 这是我的附加按钮代码
private void Addition_Click(object sender, EventArgs e)
{
dbl_FirstNumber = Convert.ToDouble(Sum.Text); //Operation Works, need to get rid of the 0
Sum.AppendText(" + ");
Here is my equal button code 这是我相等的按钮代码
private void equals_Click(object sender, EventArgs e)
{
string[] hold = Sum.Text.Split(' ');//
switch (hold[1])//holds the first number
{
case "+":
Result.Text = Convert.ToString(Convert.ToDouble(Sum.Text) + hold[0].ToString() + hold[2].ToString());
break;
My second problem 我的第二个问题
Ok so when i try put in 3 + 3 + 3 i get the error "{"Input string was not in a correct format."}" 好的,所以当我尝试输入3 + 3 + 3时,出现错误“ {”输入字符串的格式不正确。“}”
here is my addition code 这是我的附加代码
private void Addition_Click(object sender, EventArgs e)
{
dbl_FirstNumber = Convert.ToDouble(Sum.Text);
Sum.AppendText(" + ");
}
screenshot of error - https://gyazo.com/9689d4f5055d7cc9211e1c2822b1d6f3 错误的屏幕截图-https: //gyazo.com/9689d4f5055d7cc9211e1c2822b1d6f3
There are mistakes ... 有错误...
private void equals_Click(object sender, EventArgs e)
{
string[] hold = Sum.Text.Split(' ');
switch (hold[1]) // holds the DELIMTER
{
case "+":
Result.Text = Convert.ToString(Convert.ToDouble(Sum.Text) + hold[0].ToString() + hold[2].ToString());
// THATS WRONG! ^ this would take "5 + 5" and you CANNOT convert this.
// here you would Need:
Result.Text = (Convert.ToDouble(hold[0]) + Convert.ToDouble(hold[2])).ToString();
break;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.