格式异常中的错误 [英] Erreur in formatException

查看:79
本文介绍了格式异常中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用c#创建计算器所有按钮工作时我会创建使用该代码工作的punct按钮



i create calculator with c# all buttons work greate when i create the punct button with that code it work

Button num = (Button)sender;
            if (num.Text == ".")
            {

                if (!textBox9.Text.Contains("."))
                textBox9.Text = textBox9.Text + num.Text;
                    
            }





但是当我使用punct按钮进行操作时告诉我我有错误代码



but when i do the operation with the punct button the told me i have erreur in that code

Button ops = (Button)sender;
            FIRSTNUM = Double.Parse(textBox9.Text);
            textBox9.Text = "";
            OPERATION = ops.Text;
            textBox13.Text = System.Convert.ToString(FIRSTNUM) + " " + OPERATION;

推荐答案

如果是formatexception,那么它可能在线FIRSTNUM = Double.Parse(textBox9.Text);

你最好调试你的程序并确切找到这个错误出现在哪一行..

如果它在上面那么你可以找到为什么会出现这个异常,请阅读 Double.Parse [ ^ ]它清楚地说明输入是否代表一个数字一个有效的格式,然后你得到这个例外。添加一些验证,如空值检查,您也可以使用 Double.TryParse Method [ ^ ]而不是。
If it is formatexception, then it may be on line "FIRSTNUM = Double.Parse(textBox9.Text);"
you better debug your programme and find exactly which line this error occured..
If it is on above line then you can find why this exception came, read the documentation for Double.Parse[^] it clearly say if input is not represent a number in a valid format then you get this exception. Add few validations like empty value check and also you can use Double.TryParse Method[^] instead.


谢谢伙计..问题是我应该用virgule替换punct



按钮数=(按钮)发件人;

thanks Guys .. the probleme is was i should replace the punct by virgule

Button num = (Button)sender;
if (num.Text == ",")
{

    if (!textBox9.Text.Contains(","))
    textBox9.Text = textBox9.Text + num.Text;


这篇关于格式异常中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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