gpt4 book ai didi

windows-phone-7 - 异常(exception) ;类型 'System.FormatException'的异常(exception)发生在mscorlib.ni.dll但在用户代码中没有处理

转载 作者:行者123 更新时间:2023-12-01 02:25:28 24 4
gpt4 key购买 nike

您好,我有一个 Windows Phone 8 应用程序,但出现异常

An exception of type 'System.FormatException' occurred in mscorlib.ni.dll but was not handled in user code

Here are the code


  private void Button_Click_1(object sender, RoutedEventArgs e)
{
double basestolen;
double attempedstales;
double avarege;
double putout;




if (puttext.Text.Length == 0 | basetext.Text.Length==0 )
{

MessageBox.Show(" Enter Values for Base Stolen and Putouts ");

}

basestolen = Convert.ToDouble(basetext.Text);
putout = Convert.ToDouble(puttext.Text);



attempedstales = basestolen + putout;


if (attempedstales != 0 )
{

avarege = (((basestolen / attempedstales) / 100));
avarege = avarege * 10000;
avgtext.Text = Convert.ToString(avarege);


}
else
{
MessageBox.Show("Attemped Stales Value should not be Zero");
}



}

应用程序运行,如果我没有在文本框中输入值,它会返回 msg 框,但之后应用程序停止并返回上面的 exption ?问题是什么?

最佳答案

错误很可能在这里:

basestolen = Convert.ToDouble(basetext.Text);
putout = Convert.ToDouble(puttext.Text);

如果数字不是有效格式,它会抛出 FormatException。 ( see more here )。尝试使用 double.TryParse以安全的方式解析您的值。
double result;    
bool success = double.TryParse(basetext.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out result);

关于windows-phone-7 - 异常(exception) ;类型 'System.FormatException'的异常(exception)发生在mscorlib.ni.dll但在用户代码中没有处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16773019/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com