Skip to content

EN CSharp Operator Assignment

Codex edited this page Oct 11, 2026 · 2 revisions

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

Appropriation

Handbook C# · Practical Guide

Stores the value in a variable or writable member. Composite forms apply the operation and record the result without duplicating the calculation of the left side.

Simple example (Example.cs)

Save this example separately as Example.cs. Run it independently of the other examples on this page.

Example.cs:

// PROJECT-EXAMPLE
int count = 2;
count += 3;
System.Console.WriteLine(count);

Result:

5

Syntax

value = expression / value += amount

Example 1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        int value = 10;
        value += 5; value -= 2; value *= 3; value /= 2; value %= 7;
        Console.WriteLine(value);
    }
}

Example 2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        int mask = 0b0011;
        mask |= 0b0100; mask &= 0b0111; mask ^= 0b0001;
        mask <<= 2; mask >>= 1; mask >>>= 1;
        Console.WriteLine(mask);
    }
}

Official source: Microsoft Learn.

Clone this wiki locally