Skip to content

RU CSharp Operator Arithmetic

Codex edited this page Oct 11, 2026 · 2 revisions

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

Арифметика

Справочник C# · Практическое руководство

Вычисляет сумму, разницу, произведение, долю и остаток. Целочисленное деление отбрасывает дробную часть; unary +/− задает знак.

Простой пример (Example.cs)

Сохраните этот пример отдельно как Example.cs. Запускайте его независимо от остальных примеров страницы.

Example.cs:

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

Результат:

3
3.5

Синтаксис

left + right / left % right / -value

Приклад 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}");
    }
}

Приклад 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)}");
    }
}

Официальный источник: Microsoft Learn.

Clone this wiki locally