我想将输入的字符串转换为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