Skip to content

IT CSharp Operator Assignment

Codex edited this page Oct 11, 2026 · 2 revisions

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

Appropriazione

Manuale C# · Guida pratica

Memorizza il valore in una variabile o in un membro scrivibile. I moduli compositi applicano l'operazione e registrano il risultato senza duplicare il calcolo del lato sinistro.

Esempio semplice (Example.cs)

Salvare questo esempio separatamente come Example.cs. Eseguirlo indipendentemente dagli altri esempi di questa pagina.

Example.cs:

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

Risultato:

5

Sintassi

value = expression / value += amount

Esempio 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);
    }
}

Esempio 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);
    }
}

Fonte ufficiale: Microsoft Impara.

Clone this wiki locally