我是C#的新手。我試圖製作一個計算器,但發生以下錯誤:輸入字符串在double.Parse中的格式不正確
輸入字符串格式不正確。
這是代碼的摘要:
double num1, num2, result;
private void button14_Click(object sender, EventArgs e)
{
num1 = Convert.ToDouble(textBox1.Text);
textBox1.Text = String.Empty;
num2 = double.Parse(textBox1.Text); **//ERROR OCCURED HERE**
result = num1 - num2;
}
private void button13_Click(object sender, EventArgs e)
{
num1 = Convert.ToDouble(textBox1.Text);
textBox1.Text = String.Empty;
num2 = System.Double.Parse(textBox1.Text); **//ERROR OCCURED HERE**
result = num1 + num2;
}
如何字符串轉換爲雙類型?
'num!= null'?和'textBox1.Text = num;'?這會編譯? –