I'm making a guessing game where the program generates a random number from 0 to 10 and the user tries to guess it. I want the user to input an integer in a Text Area. Then I convert the input to integer. Here comes the problem: How do I do something if the input is an unconvertable string? Like "asdf". I want the program to output "I asked for a number!! not word dumbass!" but C# converts even things like "Aadsda" to 0.. what do i do?
This is what I tried:
private void button1_Click(object sender, EventArgs e)
{
try
{
int.TryParse(textBox_Guess.Text, out guess);
//IF STATEMENTS TO CHECK HOW CLOSE THE USER'S GUESS IS
}
catch (Exception)
{
//Since all strings are converted, this block is never executed
label_Reveal.ForeColor = System.Drawing.Color.Red;
label_Reveal.Text = "Your input is invalid!";
label_Reveal.Show();
}
}