Skip to content

ES CSharp Operator Increment

Codex edited this page Oct 11, 2026 · 2 revisions

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

Incremento y decremento

Manual C# · Guía Práctica

Prefijo devuelve un nuevo valor; el sufijo devuelve el anterior. Ambas formas modifican la variable.

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;
System.Console.WriteLine(count++);
System.Console.WriteLine(++count);

Resultado:

2
4

Sintaxis

++value / value++ / --value / value--

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 = 2;
        Console.WriteLine(value++); Console.WriteLine(++value);
        Console.WriteLine(value--); 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[] values = [10, 20, 30];
        int index = 0;
        while (index < values.Length) Console.WriteLine(values[index++]);
    }
}

Fuente oficial: Microsoft Aprender.

Clone this wiki locally