Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

++: practical reference

++: practical reference: ++ increases a variable by one; prefix yields the new value and postfix the old value.

Version: C# language; verified against C# 14 reference

Syntax

++operand / operand++

++ increases a variable by one; prefix yields the new value and postfix the old value.

Use it for simple counters outside shared state.

It is not atomic; concurrent code should use Interlocked.Increment.

MaxValue can wrap or throw under checked, and an overloaded ++ may do more than counting.

The complete program actually uses ++; its exact expected stdout is 4.

Examples

using System;
using System.Linq;
using System.Threading.Tasks;

var value = 3; Console.WriteLine(++value);

Result

4

The complete program actually uses `++`; its exact expected stdout is `4`.

Sources