windows-phone-7 – 例外; mscorlib.ni.dll中出现“System.Forma
发布时间:2020-12-14 05:24:59 所属栏目:Windows 来源:网络整理
导读:你好我有一个 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) {
你好我有一个
Windows Phone 8应用程序,我得到了例外
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); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |