Language: EN

csharp-operadores-aritmeticos

Arithmetic Operators in C#

Arithmetic operators are special symbols used to perform mathematical operations in C#. The basic arithmetic operators are:

OperatorNameDescription
+AdditionAdds two values
-SubtractionSubtracts the second value from the first
*MultiplicationMultiplies two values
/DivisionDivides the first value by the second
%ModuloReturns the remainder of the division of the first value by the second
++IncrementIncreases the value of a variable by one
--DecrementDecreases the value of a variable by one

List of arithmetic operators

Addition (+)

The addition operator allows us to add two values and obtain a result. For example:

int a = 5;
int b = 3;
int result = a + b; // result will be equal to 8

Subtraction (-)

The subtraction operator allows us to subtract one value from another and obtain the result. For example:

int a = 10;
int b = 7;
int result = a - b; // result will be equal to 3

Multiplication (*)

The multiplication operator allows us to multiply two values and obtain the result. For example:

int a = 4;
int b = 6;
int result = a * b; // result will be equal to 24

Division (/)

The division operator allows us to divide one value by another and obtain the result. For example:

int a = 15;
int b = 3;
int result = a / b; // result will be equal to 5

Modulo (%)

The modulo operator allows us to obtain the remainder of the division between two values. For example:

int a = 17;
int b = 5;
int result = a % b; // result will be equal to 2