Skip to content

DE CSharp Operator Arithmetic

Codex edited this page Oct 11, 2026 · 2 revisions

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

Arithmetik

Handbuch C# · Praktischer Leitfaden

Berechnet Summe, Differenz, Produkt, Quotient und Rest. Bei der Ganzzahldivision wird der Bruchteil verworfen; unary +/− setzt das Vorzeichen.

Einfaches Beispiel (Example.cs)

Speichern Sie dieses Beispiel separat als Example.cs. Führen Sie es unabhängig von den anderen Beispielen dieser Seite aus.

Example.cs:

// PROJECT-EXAMPLE
System.Console.WriteLine(7 / 2);
double quotient = 7.0 / 2;
System.Console.WriteLine(quotient.ToString(System.Globalization.CultureInfo.InvariantCulture));

Ergebnis:

3
3.5

Syntax

left + right / left % right / -value

Beispiel 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 left = 17, right = 5;
        Console.WriteLine($"{left + right}:{left - right}:{left * right}:{left / right}:{left % right}");
    }
}

Beispiel 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)
    {
        double value = 17.0 / 5.0;
        Console.WriteLine($"{+value}:{-value}:{Math.Round(value, 2)}");
    }
}

Offizielle Quelle: Microsoft Learn.

Clone this wiki locally