Im still new to C# and was wondering how one would have multiple things happen when an if condition is met. for example.
int number = (Convert.ToInt32(textbox1.text));
if (number == 1)
textbox2.Text = "1";
number2 = 33;
textbox3.text = (Convert.ToString(number2));
When I do something like this it dosnt complete all the desired results.
P.S If this isnt the right site to go for newbie questions like this does anyone know where I can go? (after research of course).
if (number == 1)
{
textbox2.Text = "1";
number2 = 33;
textbox3.text = (Convert.ToString(RSP));
}
Add brackets to group statements together.
Without the brackets, the if-statement will ONLY affect the very next statement: textbox2.Text = "1";
, and the other statements will always be run, regardless of the if-statement.
You need to use a block, using the {
and }
characters...
int number = (Convert.ToInt32(textbox1.text));
if (number == 1)
{
textbox2.Text = "1";
number2 = 33;
textbox3.text = (Convert.ToString(RSP));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With