Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception while converting String to integer in C#


I get error: Format exception was unhandled, Input string was not in a correct format.
for this line:

int right = System.Convert.ToInt32(rightAngleTB.Text);

rightAngleTB is TextBox, the value Text is "25" (without the "").

I really don´t see the problem :(

like image 287
user1097772 Avatar asked Dec 21 '22 22:12

user1097772


1 Answers

You really should use int.TryParse. It is much easier to convert and you won't get exceptions.

like image 164
Daniel A. White Avatar answered Jan 02 '23 04:01

Daniel A. White