C# “错误”;输入字符串的格式不正确。”;高斯法
我在代码和运行上遇到了一些问题 我的代码:C# “错误”;输入字符串的格式不正确。”;高斯法,c#,sharpdevelop,C#,Sharpdevelop,我在代码和运行上遇到了一些问题 我的代码: // // TODO: Add constructor code after the InitializeComponent() call. // textBox1.Text=("0.42"); textBox2.Text=("1.14"); textBox3.Text=("-0.71"); textBox4.Text=("-1.13"); textBox5.Tex
//
// TODO: Add constructor code after the InitializeComponent() call.
//
textBox1.Text=("0.42");
textBox2.Text=("1.14");
textBox3.Text=("-0.71");
textBox4.Text=("-1.13");
textBox5.Text=("-2.15");
textBox6.Text=("0.81");
textBox7.Text=("7.05");
textBox8.Text=("5.11");
textBox9.Text=("-0.02");
textBox10.Text=("6.15");
textBox11.Text=("-4.16");
textBox12.Text=("-0.17");
}
void Button1Click(object sender, EventArgs e)
{
double z1,z2,z3,x1,x2,x3,c1,c2,c3,a1,a2,a3,n,s1,s2,s3;
z1=Convert.ToDouble(textBox1.Text);
z2=Convert.ToDouble(textBox2.Text);
z3=Convert.ToDouble(textBox3.Text);
x1=Convert.ToDouble(textBox4.Text);
x2=Convert.ToDouble(textBox5.Text);
x3=Convert.ToDouble(textBox6.Text);
c1=Convert.ToDouble(textBox7.Text);
c2=Convert.ToDouble(textBox8.Text);
c3=Convert.ToDouble(textBox9.Text);
a1=Convert.ToDouble(textBox10.Text);
a2=Convert.ToDouble(textBox11.Text);
a3=Convert.ToDouble(textBox12.Text);
n=x1/z1;
textBox24.Text=Convert.ToString(z1=n*z1);
textBox23.Text=Convert.ToString(z2=n*z2);
textBox22.Text=Convert.ToString(z3=n*z3);
textBox19.Text=Convert.ToString(x1=x1-z1);
textBox20.Text=Convert.ToString(x2=x2-z2);
textBox21.Text=Convert.ToString(x3=x3-z3);
textBox13.Text=Convert.ToString(a1=a1*n);
textBox14.Text=Convert.ToString(a2=a2-a1);
n=c1/z1;
textBox24.Text=Convert.ToString(z1=n*z1);
textBox23.Text=Convert.ToString(z2=n*z2);
textBox22.Text=Convert.ToString(z3=n*z3);
textBox16.Text=Convert.ToString(c1=c1-z1);
textBox17.Text=Convert.ToString(c2=c2-z2);
textBox18.Text=Convert.ToString(c3=c3-z3);
textBox13.Text=Convert.ToString(a1=a1*n);
textBox15.Text=Convert.ToString(a3=a3-a1);
n=c2/x2;
textBox32.Text=Convert.ToString(x2=x2*n);
textBox33.Text=Convert.ToString(x3=x3*n);
textBox29.Text=Convert.ToString(c2=c2-x2);
textBox30.Text=Convert.ToString(c3=c3-x3);
textBox26.Text=Convert.ToString(a2=a2*n);
textBox27.Text=Convert.ToString(a3=a3-a2);
textBox36.Text=textBox24.Text;
textBox35.Text=textBox23.Text;
textBox34.Text=textBox22.Text;
textBox25.Text=textBox13.Text;
n=(1/c3);
s1=Math.Round(n*a3,4);
label28.Text=("c="+s1);
s2=Math.Round((1/x2)*(a2-(x3*s1)),4);
label29.Text=("b="+s2);
s3=Math.Round((1/z1)*(a1-(z2*s2)-(z3*s1)),4);
label30.Text=("a="+s3);
}
}
本程序是高斯法练习
当我运行程序时,我尝试按下按钮,但随后错误弹出:
System.FormatException:输入字符串的格式不正确。
在System.Number.ParseDouble(字符串值、NumberStyles选项、NumberFormatInfo numfmt)
at System.Convert.ToDouble(字符串值)
在gausa_metode_2_variants.MainForm.button1点击c:\Users\NIKS\Documents\SharpDevelop Projects\gausa metode 2 variants\gausa metode 2 variants\MainForm.cs中的(对象发送者,事件参数e):第48行
在System.Windows.Forms.Control.OnClick(EventArgs e)中
在System.Windows.Forms.Button.OnClick(EventArgs e)中
在System.Windows.Forms.Button.OnMouseUp(MouseEventArgs-mevent)上
在System.Windows.Forms.Control.WmMouseUp(Message&m、MouseButtons按钮、Int32单击)
位于System.Windows.Forms.Control.WndProc(Message&m)
位于System.Windows.Forms.ButtonBase.WndProc(Message&m)
在System.Windows.Forms.Button.WndProc(Message&m)中
在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)中
在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)中
在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd、Int32 msg、IntPtr wparam、IntPtr lparam)
在System.Windows.Forms.UnsafentiveMethods.DispatchMessageW(MSG&MSG)中
位于System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafentiveMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID、Int32 reason、Int32 pvLoopData)
位于System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32原因,ApplicationContext上下文)
位于System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32原因,ApplicationContext上下文)
在System.Windows.Forms.Application.Run(Form mainForm)中
在c:\Users\NIKS\Documents\sharpdevelopment Projects\gausa metode 2 variants\gausa metode 2 variants\Program.cs中的gausa\u metode\u variants.Main(字符串[]args)处
它无法在这些行中分析字符串以使其加倍
z1=Convert.ToDouble(textBox1.Text);
z2=Convert.ToDouble(textBox2.Text);
z3=Convert.ToDouble(textBox3.Text);
x1=Convert.ToDouble(textBox4.Text);
x2=Convert.ToDouble(textBox5.Text);
x3=Convert.ToDouble(textBox6.Text);
c1=Convert.ToDouble(textBox7.Text);
c2=Convert.ToDouble(textBox8.Text);
c3=Convert.ToDouble(textBox9.Text);
a1=Convert.ToDouble(textBox10.Text);
a2=Convert.ToDouble(textBox11.Text);
a3=Convert.ToDouble(textBox12.Text);
当我选中文本框时,值似乎很好。没有问题,可能您正在运行时更改textbox的值。
最后,错误消息显示:
System.FormatException: Input string was not in a correct format.
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Convert.ToDouble(String value) at line 48
因此,只需检查您试图在第48行分析的值,您在将第48行中指定的
字符串
转换为双精度
时遇到问题。
这将是一个**=Convert.ToDouble(textBox*.Text)代码>
根据地区和地区设置,我非常确定您需要为十进制分隔符编写,
(至少有些国家使用,
而不是,
)。如果我的回答对您有所帮助,请给我一个赞成票。谢谢。
System.FormatException: Input string was not in a correct format.
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Convert.ToDouble(String value) at line 48