How to do simple mathematical operations and display the result in a text box

I know this is a pretty simple question, but I just can't find a suitable example on Google or anywhere.

I have this part

int numberOfPlays = int.Parse(textBox2.Text);
numberOfPlays = (numberOfPlays++);
textBox2.Text = (numberOfPlays.ToString()); 
MessageBox.Show(numberOfPlays.ToString());

So basically, what I want to do is get the value of textBox2, make it an integer, and then add 1 to it.

Now I can not come up with any details, so if I'm not clear enough, ask

Thanks in advance

+3
source share
4 answers

This line is incorrect:

numberOfPlays = (numberOfPlays++);

You just need

numberOfPlays++;

Otherwise, you rewrite the changes with the old value (note that the value (numberOfPlays++)is "old", before the increment).

+1
source

Edit

 numberOfPlays = (numberOfPlays++);

simply

 numberOfPlays++; 
0

:

numberOfPlays++;

Otherwise, a post increment operator is used (as the name says) after the value numberOfPlaysis assigned again numberOfPlays- that will not change anything.

0
source

To expand on what others have said,

numberOfPlays++

Same as

numberOfPlays += 1

Same as

numberOfPlays = numberOfPlays + 1
0
source

Source: https://habr.com/ru/post/1742796/


All Articles