如何解决错误操作符' - '不能应用于'float'和'string'类型的操作数 [英] How to solve error operator '-' cannot be applied to operands of type 'float' and '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.
这篇关于如何解决错误操作符' - '不能应用于'float'和'string'类型的操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文