获得在2个文本框中定期更新的值的总和C#

问题描述 投票:0回答:1

我有两个定期更新的文本框,每个文本框都通过串行端口在一行上显示数据,我想从这些文本框中获取这些值的总和并将其放入另一个文本框。

代码:

textbox1.text = value1;
textbox2.text = value2;

value3 = value1 + value2;
textbox3.text = value3;

输出文本框1:

100, after sometime updates to 200, then 300

输出文本框2:

50, after sometime updates to 100, then 150

我得到的,在textbox3中输出:

150, after some time updates to 300, then 450

我应该得到的值是

100+200+300+50+100+150
c# forms textbox sum
1个回答
-1
投票

当您从C#的文本字段获取输入时,您将获得字符串数据作为输入。对于整数运算,您需要使用Parse方法将字符串输入转换为文本。

尝试

Int16.Parse()
Int32.Parse()
Int64.Parse()
© www.soinside.com 2019 - 2024. All rights reserved.