我想將輸入的字符串轉換爲int。我曾嘗試int.parse,並int.parse32但是當我按 「回車」 我得到以下錯誤:將字符串轉換爲整數C#
System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options,
NumberBuffer & number...."
部分Form1類:
this.orderID.Text = currentID;
this.orderID.KeyPress += new KeyPressEventHandler(EnterKey);
部分Form1類:形式:
public int newCurrentID;
private void EnterKey(object o, KeyPressEventArgs e)
{
if(e.KeyChar == (char)Keys.Enter)
{
try
{
newCurrentID = int.Parse(currentID);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
e.Handled = true;
}
}
把一個破發點,以法'EnterKey',看看'currentID'包含。 – I4V 2013-05-14 07:11:09
currentID是什麼類型,它的內容是什麼? – 2013-05-14 07:12:04
當你解析它時你在currentID裏面找到了什麼 – tariq 2013-05-14 07:14:29