Reputation: 2509
I know is a rather simple question but I just can't find an appropriate example in google or anywhere.
I've got this piece
int numberOfPlays = int.Parse(textBox2.Text);
numberOfPlays = (numberOfPlays++);
textBox2.Text = (numberOfPlays.ToString());
MessageBox.Show(numberOfPlays.ToString());
So basically what I want to do is to get the value of the textBox2, make it an integer and then add 1 to it.
I can't think of any more details right now, so if i'm not clear enough please ask
Thanks in advance
Upvotes: 3
Views: 228
Reputation: 3106
To expand on what the others have said,
numberOfPlays++
Is the same as
numberOfPlays += 1
Is the same as
numberOfPlays = numberOfPlays + 1
Upvotes: 0
Reputation: 53924
You should write:
numberOfPlays++;
Otherwise the post increment operator is applied (as the name says) after the value of numberOfPlays
is assigned to numberOfPlays
again - which will not change anything.
Upvotes: 0
Reputation: 9244
Change
numberOfPlays = (numberOfPlays++);
to just
numberOfPlays++;
Upvotes: 0
Reputation: 35584
This line is wrong:
numberOfPlays = (numberOfPlays++);
You need just
numberOfPlays++;
Otherwise you are overwriting the changes with the old value (note that the value of (numberOfPlays++)
is the "old" one, before increment).
Upvotes: 1