EN CSharp Operator Arithmetic - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Arithmetic
Calculates sum, difference, product, quotient and remainder. Integer division discards the fractional part; unary +/− sets the sign.
Simple example (Example.cs)
Save this example separately as Example.cs. Run it independently of the other examples on this page.
Example.cs:
// PROJECT-EXAMPLE
System.Console.WriteLine(7 / 2);
double quotient = 7.0 / 2;
System.Console.WriteLine(quotient.ToString(System.Globalization.CultureInfo.InvariantCulture));
Result:
3
3.5
Syntax
left + right / left % right / -value
Example 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}");
}
}
Example 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)}");
}
}
Official source: Microsoft Learn.