Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Increment or Decrement a Variable

From Groundhog Learning

Change a variable value by a certain amount.

Increment or Decrement a Variable in C#

Increment a Variable in C#

💻 C#

int score = 0;

// Increment by 1
score = score + 1;   // traditional
score += 1;          // shorthand
score++;             // shortcut

Decrement a Variable in C#

💻 C#

int lives = 3;

// Decrement by 1
lives = lives - 1;   // traditional
lives -= 1;          // shorthand
lives--;             // shortcut

Related Concepts