如何解决错误操作符' - '不能应用于'float'和'string'类型的操作数

如何解决错误操作符' - '不能应用于'float'和'string'类型的操作数

问题描述:

如何解决错误操作符' - '不能应用于'float'和'string'类型的操作数



我尝试过:



How to solve Error Operator '-' cannot be applied to operands of type 'float' and 'string'

What I have tried:

private void textBox4_TextChanged(object sender, EventArgs e)
{
    try
    {
        textBox5.Text=(float.Parse(textBox3.Text) - float.Parse(textBox4.Text).ToString());
    }
    catch
    {

    }
}

检查括号。

您的代码:

Check the parentheses.
Your code:
textBox5.Text=(float.Parse(textBox3.Text) - float.Parse(textBox4.Text).ToString());

正确:

Correct:

textBox5.Text=(float.Parse(textBox3.Text) - float.Parse(textBox4.Text)).ToString();


替换

Replace
textBox5.Text=(float.Parse(textBox3.Text) - float.Parse(textBox4.Text).ToString());



with


with

textBox5.Text=(float.Parse(textBox3.Text) - float.Parse(textBox4.Text)).ToString();



和往常计算机程序一样,每件事都很重要,缺少空间,()的位置......



建议:使用像NotePad ++这样的程序员编辑器,他们会告诉你如何()与其他东西匹配。


As usual with computer programs everyt
thing matters, missing space, position of () ...

Advice: use programmer editor like NotePad++, they show you how () are matching among other things.