1

入力された文字列を int に変換しようとしています。int.parseint.parse32を試しましたが、「Enter」を押すと次のエラーが表示されます。

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:Form:

  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;
        }
    }
4

4 に答える 4

4

文字列をチェックしstring.IsNullOrEmpty()、そのような文字列を解析しようとしません。

于 2013-05-14T07:12:13.773 に答える