tags:

views:

66

answers:

4

Hi, 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

+1  A: 

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).

Vlad
And I knew it was something stupid ;pThanks so much =]
Audel
You're welcome!
Vlad
A: 

Change

 numberOfPlays = (numberOfPlays++);

to just

 numberOfPlays++; 
danbystrom
A: 

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.

tanascius
A: 

To expand on what the others have said,

numberOfPlays++

Is the same as

numberOfPlays += 1

Is the same as

numberOfPlays = numberOfPlays + 1
Harry