Basic Arithmetic Operators in C#, include the following −
| Operator | Description |
|---|---|
| + | Adds two operands |
| - | Subtracts the second operand from the first |
| * | Multiplies both operands |
| / | Divides the numerator by de-numerator |
| % | Modulus Operator and remainder of after an integer division |
| ++ | Increment operator increases integer value by one |
| -- | Decrement operator decreases integer value by one |
To add, use the Addition Operator −
num1 + num2;
In the same way, it works for Subtraction, Multiplication, Division, and other operators.
Example
Let us see a complete example to learn how to implement Arithmetic operators in C#.
using System;
namespace Sample {
class Demo {
static void Main(string[] args) {
int num1 = 50;
int num2 = 25;
int result;
result = num1 + num2;
Console.WriteLine("Value is {0}", result);
result = num1 - num2;
Console.WriteLine("Value is {0}", result);
result = num1 * num2;
Console.WriteLine("Value is {0}", result);
result = num1 / num2;
Console.WriteLine("Value is {0}", result);
result = num1 % num2;
Console.WriteLine("Value is {0}", result);
result = num1++;
Console.WriteLine("Value is {0}", result);
result = num1--;
Console.WriteLine("Value is {0}", result);
Console.ReadLine();
}
}
}Output
Value is 75 Value is 25 Value is 1250 Value is 2 Value is 0 Value is 50 Value is 51