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
Revision as of 16:08, 21 October 2025 by Groundhog (talk | contribs) (Updated via bot)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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