Is there some way to convert a string which consists of a number(eg. 24) to an integer type? I am trying to get the value from the text property of a text box.
Be sure to wrap that code in a try...catch block in case someone enters
invalid data, like this:
try
{
int n = int.Parse("24");
int n = int.Parse(TextBox1.Text);
}
catch (Exception ex)
{
// Do something to indicate TextBox1 does not contain a valid integer
}
You could also trap for the specific exceptions that Parse can throw, which
are FormatException, ArgumentException and OverflowException.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.