Jump to content

c# increment and decrement counter

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
nikiarora

nikiarora

    Newbie

  • Members
  • Pip
  • 1 posts
I want to make increment and decrement counter.
There are two buttons called X and Y. First press X and then press Y counter should increment.
First press Y and then press X counter should decrement.

I am not familiar with c#. So can anyone help me please ?? :(

#2
ArekBulski

ArekBulski

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,376 posts
By counters do you mean variables? Declare a variable in the form class.

int counterX = 0;
int counterY = 0;

Then double-click a button and there (in the Click event handler, but sounds a bit tech'ie) you put an incrementation statement.

counterX++; 
//or
counterY--;

Does it help ya? ;)

#3
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
That is how you would need to do it is with two variables and either the post-decrement or post-increment operators.

Basically x++ means to increase x by one after evaluating x. Thus, x-- means after evaluating x to decrease x by one. If you place the ++ and -- before the variable names then the variables are incremented or decremented before they are evaluated.