Windows phone 7 例外情况;类型为';System.FormatException';在mscorlib.ni.dll中发生,但未在用户代码中处理
你好,我有一个windows phone 8应用程序,我遇到异常 mscorlib.ni.dll中发生“System.FormatException”类型的异常,但未在用户代码中处理 这是密码Windows phone 7 例外情况;类型为';System.FormatException';在mscorlib.ni.dll中发生,但未在用户代码中处理,windows-phone-7,c#-4.0,windows-phone-8,Windows Phone 7,C# 4.0,Windows Phone 8,你好,我有一个windows phone 8应用程序,我遇到异常 mscorlib.ni.dll中发生“System.FormatException”类型的异常,但未在用户代码中处理 这是密码 应用程序运行,如果我没有在文本框中输入值,它将返回消息框,但在这之后,应用程序停止并返回上面的表达式?问题是什么?在显示消息框后,您忘记停止方法的执行: if (puttext.Text.Length == 0 || basetext.Text.Length==0 ) { MessageBox.S
应用程序运行,如果我没有在文本框中输入值,它将返回消息框,但在这之后,应用程序停止并返回上面的表达式?问题是什么?在显示消息框后,您忘记停止方法的执行:
if (puttext.Text.Length == 0 || basetext.Text.Length==0 )
{
MessageBox.Show(" Enter Values for Base Stolen and Putouts ");
return;
}
此外,将字符串转换为双精度时,请确保指定区域性。您的Windows Phone应用程序将由世界各地的用户执行,有些国家使用不同的十进制分隔符。例如:
basestolen = Convert.ToDouble(basetext.Text, CultureInfo.InvariantCulture);
此处最有可能出现错误:
basestolen = Convert.ToDouble(basetext.Text);
putout = Convert.ToDouble(puttext.Text);
如果数字的格式无效,它将引发FormatException。(). 尝试使用以安全的方式解析您的值
double result;
bool success = double.TryParse(basetext.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out result);
double result;
bool success = double.TryParse(basetext.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out result);