I don't think it needs to convert to string at the line: "temp = textBox1.Text.ToString();" because it really a string.
If you don't want to get a FormatException, you can use the method double.TryParse(...) or int.TryParse(...), but its inconvenience is that you should check the output value may be null or not. On Sat, Aug 1, 2009 at 3:09 PM, Cerebrus <[email protected]> wrote: > > Convert.ToInt32(string) internally calls Int32.Parse(string). > > It will throw a FormatException if the supplied string is not a valid > number. > > On Aug 1, 7:00 am, Rafael Anschau <[email protected]> wrote: > > private void button1_MouseClick(object sender, MouseEventArgs e) > > { > > > > string temp; > > temp = textBox1.Text.ToString(); > > double temp2; > > temp2 = Convert.ToInt32(temp); > > > > } > > > > It compiles fine, but I get the runtime error "Format exception was > > unhandled"" Input > > string was not in a correct format" when the button is clicked. The > > line it highlights is > > temp2 = Convert.ToInt32(temp). > -- kidVN
