如何进行数据转换?(100分)

  • 主题发起人 主题发起人 千中元
  • 开始时间 开始时间

千中元

Unregistered / Unconfirmed
GUEST, unregistred user!
通过TextBox来输入年龄。
TextBox的ID属性为tbAge.
程序中代码为:
int Age = Convert.ToInt32(tbAge.Text.Trim());
调试,出现异常,
异常详细信息: System.FormatException: 输入字符串的格式不正确。
源错误:行 71: int Age = Convert.ToInt32(tbAge.Text.Trim());
 
try
{
int aa;
aa =(Int32.Parse(this.textBox1.Text));
this.textBox2.Text =aa.ToString();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
这段代码是没有问题的
 
我在进行数据类型转换很少用Convert,都是直接转换比较多
不过这句:int Age = Convert.ToInt32(tbAge.Text.Trim());应该也没有问题呀
 
接受答案了.
 
后退
顶部