试试以下代码
int x;if(int.TryParse(textBox1.Text, out x)){ Console.WriteLine(x);}else{ Console.WriteLine("无法转换");}
int n = Convert.Toint32(textbox.Text);