Skip to content

ES CSharp Operator Assignment

Codex edited this page Oct 11, 2026 · 2 revisions

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

Apropiación

Manual C# · Guía Práctica

Almacena el valor en una variable o miembro grabable. Los formularios compuestos aplican la operación y registran el resultado sin duplicar el cálculo del lado izquierdo.

Ejemplo sencillo (Example.cs)

Guarde este ejemplo por separado como Example.cs. Ejecútelo independientemente de los demás ejemplos de esta página.

Example.cs:

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

Resultado:

5

Sintaxis

value = expression / value += amount

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

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

Fuente oficial: Microsoft Aprender.

Clone this wiki locally