当我尝试下面的代码时收到错误 [英] getting error when i try this following code

查看:64
本文介绍了当我尝试下面的代码时收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

double days = Convert.ToDouble(textbox1.Text);
           double sundays = Convert.ToDouble(textbox2.Text);
           double a = Convert.ToDouble(textbox3.text);
           textbox4.text = Convert.ToDouble((a / days) * sundays).ToString();




我尝试使用此代码,但是我按清除按钮时出现错误

输入的字符串格式不正确.在第一行中.


清除按钮代码,如下所示




i try this code it is working but when i press clear button error occurs

the input string was not in correct format.in the first line.


clear button code as follows

textbox1.text = "";
           textbox2.text = "";
           textbox3.text = "";
           textbox4.text = "";




请发送验证码.




please send the code. help me.

推荐答案

清除textboxes too后转换代码是否还在运行.

我认为清除textbox 后,转换正在发生,并且正在给出异常.

我建议使用Double.TryParse只是为了使其更健壮.并尝试进行转换之前,请检查textboxes 是否为空或是否填充有某些值.



Is your conversion code running after clearing the textboxes too.

I think after clearing the textbox the conversion is happening and is giving exception.

I suggest use of Double.TryParse just to make it little robust. and before trying to convert check whether the textboxes are empty or filled with some value.

i.e.

if(textbox1.Text != string.Empty)
{
  double days = Double.TryParse(textbox1.Text);
}


这篇关于当我尝试下面的代码时收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆